careteditor / issues

Caret issues
https://caret.io
325 stars 12 forks source link

Tab key doesn't insert tab as expected #134

Open AzavarSteve opened 8 years ago

AzavarSteve commented 8 years ago

I cannot insert tabs between words. Instead, it indents the whole line as if I had hit tab at the beginning of the line. I would expect the tab key to insert a tab where my cursor is.

version 1.7.0

erusev commented 8 years ago

@AzavarSteve

Thanks for getting in touch.

Could you tell us a use case where inserting tabs in the middle of a line makes sense?

We couldn't find one when we implemented the feature :|

AzavarSteve commented 8 years ago

Sure, in this particular instance I was entering some tabular data such as rows and columns of data. I would still like to be able to copy/paste these rows of data into the editor and still work with them. However, if these pasted rows contain tabs then the editor kind of starts acting strange. E.g. I can place my cursor at a tab, delete it, then hit tab again, only now the tab inserts at the beginning of the line instead of at my cursor. So while I understand tabs may not render as anything in the HTML output (currently), the source code of the document should still honor the authors intention that a tab exist at that position in the source.

Like any printable character on the keyboard (with few exceptions such as backspace and delete), when we type it we expect it to appear at the cursor location. Other applications behave in a similar manner such as Notepad, Notepad++, Word, WordPad, etc, so my expectation was that Caret would honor that same behavior, if for no reason other than for uniformity.

Having said that, I think the behavior would be correct if you were typing in the formatted side of the editor. Since a tab has no purpose in that view, its purpose could be construed to mean indent in this context.

I understand the challenges of building an editor such as this, and its not an easy task. Hope this helps!

gandalfsaxe commented 6 years ago

Indenting a line no matter where you press tab in it is quite an old behavior and feels obsolete now.

What most modern text editors does is this:

  1. Tab is tab. I.e. only indents of cursor is first in the line.
  2. Ctrl+[ is indent, Ctrl+] is unindent (Cmd for Mac).

Would be great to have it working like this in Caret too. Impossible to align certain things with tab as it is now.

gandalfsaxe commented 6 years ago

Btw I'm a fan of tabs actually being X number of spaces 👍

Some would perhaps prefer actual tabs, but I always want spaces, so it's good with me.