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

Commit 4e66521

Browse files
author
Narciso Jaramillo
committed
For #5068, when autoindenting, only insert a tab if the cursor doesn't move due to CodeMirror's indentation
1 parent 9a92eeb commit 4e66521

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/editor/Editor.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,18 @@ define(function (require, exports, module) {
140140
if (indentAuto) {
141141
var currentLength = line.length;
142142
CodeMirror.commands.indentAuto(instance);
143-
// If the amount of whitespace didn't change, insert another tab
143+
144+
// If the amount of whitespace and the cursor position didn't change, we must have
145+
// already been at the correct indentation level as far as CM is concerned, so insert
146+
// another tab.
144147
if (instance.getLine(from.line).length === currentLength) {
145-
insertTab = true;
146-
to.ch = 0;
148+
var newFrom = instance.getCursor(true),
149+
newTo = instance.getCursor(false);
150+
if (newFrom.line === from.line && newFrom.ch === from.ch &&
151+
newTo.line === to.line && newTo.ch === to.ch) {
152+
insertTab = true;
153+
to.ch = 0;
154+
}
147155
}
148156
} else if (instance.somethingSelected() && from.line !== to.line) {
149157
CodeMirror.commands.indentMore(instance);

0 commit comments

Comments
 (0)