No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to get Cursor Position from q-editor?

    Help
    3
    3
    551
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • K
      kamrava last edited by

      I need access to the current cursor position in the q-editor.
      I also looked at this thread:
      https://forum.quasar-framework.org/topic/4702/how-to-get-the-cursor-position-form-q-input/5

      But the above link only works for q-input

      The following code returns cursorPos: undefined on the console.

      <q-editor v-model="text" ref="editorval" @input="changeInput"/>
      

      and

      changeInput(value) {
         let editor = this.$refs.editorval
         if (editor) {
           this.cursorPosition = editor.selectionStart;
           console.log('cursorPos:', this.cursorPosition)
         }
         this.cursorPosition = 0;
      }
      

      What is the correct way to do this?

      1 Reply Last reply Reply Quote 0
      • D
        DorianSOS last edited by DorianSOS

        try this

        changeInput (value) {
              console.log(this.$refs.editorval.$refs.content)
              const content = this.$refs.editorval.$refs.content
              if (content) {
                if (window.getSelection) { // ie11 10 9 ff safari
                  var range = window.getSelection()
                  console.log(range)
                  this.cursorPosition = range.focusOffset
                  console.log('cursorPos:', this.cursorPosition)
                }
                this.cursorPosition = 0
              }
            }
        
        Q 1 Reply Last reply Reply Quote 0
        • Q
          QuasarDeveloper @DorianSOS last edited by

          @DorianSOS This works on only one line. When a user creates a new line the cursor does not follow that

          1 Reply Last reply Reply Quote 0
          • First post
            Last post