sunmoon1983

各位大佬们, uni-app 中可以监听 uni-esayinput 的光标移动事件吗?

  •  
  •   sunmoon1983 · Jun 29, 2024 · 1367 views
    This topic created in 686 days ago, the information mentioned may be changed or developed.

    就像 QQ 的聊天输入框一样,我先输入十个字,然后把光标移动到第三个字后面,这时候我想记录一下光标的位置,然后在当前位置插入一个 emoji 表情, 请问有这种事件吗? 今天我尝试了 focue 和 input 事件,貌似都不太行! 主要的代码:

          <uni-easyinput
            v-if="sendMsgWay === 0"
            class="builder-main__content"
            confirmType="send"
            ref="easyInput"
            :placeholder="placeholder"
            :clearable="false"
            v-model="message"
            @input="onInput"
            @focus="onInputFocus"
            @blur="onInputBlur"
            @confirm="onSendMessage"
          />
    
    const cursorPosition = ref({})
    //记录光标位置
    const updateCursorPosition = ()=>{
      uni.getSelectedTextRange({
        success: res => {
          cursorPosition.value = {...res}
        }
      })
    }
    function onInputFocus(e) {
      updateCursorPosition();
    }
    function onInputBlur(){
      updateCursorPosition();
    }
    function onInput(){
      updateCursorPosition();
    }
    

    一个主要的现象就是,文字输入完成,移动光标到某个字后面,emoji 表情就会插入到文字的最后,这时候我再移动光标,再插入 emoji,貌似位置以正确了

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3892 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 00:09 · PVG 08:09 · LAX 17:09 · JFK 20:09
    ♥ Do have faith in what you're doing.