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

When autoindenting, only insert a tab if the cursor doesn't move due to CodeMirror's indentation #5815

Merged
merged 1 commit into from
Nov 3, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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