Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Commit

Permalink
For #5068, when autoindenting, only insert a tab if the cursor doesn'…
Browse files Browse the repository at this point in the history
…t move due to CodeMirror's indentation
  • Loading branch information
Narciso Jaramillo committed Nov 1, 2013
1 parent 9a92eeb commit 4e66521
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,18 @@ define(function (require, exports, module) {
if (indentAuto) {
var currentLength = line.length;
CodeMirror.commands.indentAuto(instance);
// If the amount of whitespace didn't change, insert another tab

// If the amount of whitespace and the cursor position didn't change, we must have
// already been at the correct indentation level as far as CM is concerned, so insert
// another tab.
if (instance.getLine(from.line).length === currentLength) {
insertTab = true;
to.ch = 0;
var newFrom = instance.getCursor(true),
newTo = instance.getCursor(false);
if (newFrom.line === from.line && newFrom.ch === from.ch &&
newTo.line === to.line && newTo.ch === to.ch) {
insertTab = true;
to.ch = 0;
}
}
} else if (instance.somethingSelected() && from.line !== to.line) {
CodeMirror.commands.indentMore(instance);
Expand Down

0 comments on commit 4e66521

Please sign in to comment.