refactory-id / bootstrap-markdown

Bootstrap plugin for markdown editing
Apache License 2.0
1.99k stars 371 forks source link

why put the cursor to the end when press tab? #124

Open Gwill opened 9 years ago

Gwill commented 9 years ago

The source code like this,

        case 9: // tab
          var nextTab
          if (nextTab = this.getNextTab(),nextTab != null) {
            // Get the nextTab if exists
            var that = this
            setTimeout(function(){
              that.setSelection(nextTab.start,nextTab.end)
            },500)

            blocked = true
          } else {
            // The next tab memory contains nothing...
            // check the cursor position to determine tab action
            var cursor = this.getSelection()

            if (cursor.start == cursor.end && cursor.end == this.getContent().length) {
              // The cursor already reach the end of the content
              blocked = false

            } else {
              // Put the cursor to the end
              this.setSelection(this.getContent().length,this.getContent().length)

              blocked = true
            }
          }
toopay commented 9 years ago

There are some case whereas the editor instance need to go backward, eg : when you select an image. The editor will allow you to rewrite the image title/tag, then after there is no next tab in its memory, the editor will put the cursor at the end on the line. Thats the story behind this behaviour, and i think its pretty sensible to have it as default.

JRawly commented 6 years ago

I believe this is having another, unexpected, issue.

We use your library on our software, and we have had reports of the cursor being set to the end of the text field (not the end of the line) when alt-tabbing between windows, when using Windows.

If you are using a Mac, and alt-tab between windows, or even just press tab in the textarea, the tab is not recognised as a key press on the field and so the same does not occur (this is a good thing).