Skip to content

[sublime] Sublime-style smart backspace#3127

Closed
vincentwoo wants to merge 1 commit intocodemirror:masterfrom
vincentwoo:master
Closed

[sublime] Sublime-style smart backspace#3127
vincentwoo wants to merge 1 commit intocodemirror:masterfrom
vincentwoo:master

Conversation

@vincentwoo
Copy link
Copy Markdown
Contributor

In Sublime, when you hit backspace, the editor checks to see if everything proceeding your cursor is whitespace. If it is, and your cursor is on an even multiple of the tab size, it will simply delete one full tab, which is pretty nice.

I've tried to mimic this here. It's a bit hacky without some defined API for figuring out the real length of hard vs soft tabs but I think this suffices. Thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use CodeMirror.countColumn(cm.getLine(cursor.line), cursor.ch, tabSize) to get the column at which the cursor is. That's probably cleaner.

@vincentwoo
Copy link
Copy Markdown
Contributor Author

Okay, I took your advice on countColumn. I also registered the function in the commands map, which I hope you don't mind. I think it's a useful one.

@vincentwoo vincentwoo closed this Mar 13, 2015
@vincentwoo vincentwoo reopened this Mar 13, 2015
marijnh added a commit that referenced this pull request Mar 14, 2015
@marijnh
Copy link
Copy Markdown
Member

marijnh commented Mar 14, 2015

Thanks. Merged as 8dbb84f and tweaked in 33e56fb. I figured indentUnit is a more appropriate value to check the modulo of, since that's what indentSelection will actually shift the line by, and what most modes use as the base unit of indentation.

@marijnh marijnh closed this Mar 14, 2015
@vincentwoo
Copy link
Copy Markdown
Contributor Author

Thanks! Out of curiosity, can you explain how/when indentUnit and tabSize differ?

@marijnh
Copy link
Copy Markdown
Member

marijnh commented Mar 14, 2015

They should usually be set to the same value, but indentUnit is the unit of indentation, and tabsize is the width of a tab. Those are not necessarily the same.

marijnh added a commit that referenced this pull request May 17, 2016
@marijnh
Copy link
Copy Markdown
Member

marijnh commented May 17, 2016

I've reverted this in 55a47a5, because

  • It breaks when there are multiple cursors, which is something the rest of the sublime bindings take care to handle
  • I couldn't get sublime text to actually show this behavior by default. If I press backspace after leading spaces, even when on a tab-count boundary, it still simply deletes the space before the cursor

See #4023

@vincentwoo
Copy link
Copy Markdown
Contributor Author

My colleagues and I see this default backspace behavior on sublime 2 and 3, with no customizations to the keybindings. It might be relevant that we all use OSX. Would you be okay with merging a version of this that works correctly with multiple cursors? I can take a crack at it.

@marijnh
Copy link
Copy Markdown
Member

marijnh commented May 26, 2016

Sure, I'd merge a proper implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants