Skip to content

input-selection-end event isn't firing correctly in some cases #10106

@AllanChain

Description

@AllanChain

Search first

  • I searched and no similar issues were found

What Happened?

Plugins use logseq.Editor.onInputSelectionEnd(...) to listen to the input-selection-end event. However, there are some cases in which the event is firing or not firing unexpectedly:

  • Not firing when the selection ends with mouseup outside the textarea
  • Firing again when clicking on the selection or beyond the end of the text.

See below for detailed reproduction.

Reproduce the Bug

  1. Create a simple plugin to listen to the input-selection-end event
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Logseq selection bug</title>
</head>
<body>
<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/@logseq/libs"></script>
<script src="./index.js"></script>
</body>
</html>
function main () {
  logseq.Editor.onInputSelectionEnd(console.log)
}

// bootstrap
logseq.ready(main).catch(console.error)
{
  "name": "logseq-selection-bug",
  "version": "1.0.0",
  "description": "",
  "main": "index.html",
  "logseq": {
    "id": "logseq-selection-bug"
  },
  "license": "MIT"
}
  1. Open Logseq, create a block with the text Something
  2. (Follow the screenshots)
    1. Select Something and mouse up without leaving the textarea (firing, expected)
    2. Click on the selection (firing, unexpected)
    3. Same as (i)
    4. Click beyond the end of the selection (firing, unexpected)
    5. Select Something and mouse up outside the textarea (not firing, unexpected)
    6. Same as (ii)

Expected Behavior

  • The result should be
    1. firing
    2. not firing
    3. firing
    4. not firing
    5. firing
    6. not firing

Screenshots

logseq-selection-bug

Desktop or Mobile Platform Information

Linux, Desktop App 0.9.15

Additional Context

Is there a specific reason why mouseup is used instead of select? I need to figure this out before working on the PR.

(. el addEventListener "mouseup"
#(let [start (util/get-selection-start el)
end (util/get-selection-end el)]
(when (and start end)
(when-let [e (and (not= start end)
{:caret (cursor/get-caret-pos el)
:start start :end end
:text (. (.-value el) substring start end)
:point {:x (.-x %) :y (.-y %)}})]
(plugin-handler/hook-plugin-editor :input-selection-end (bean/->js e)))))))

Are you willing to submit a PR? If you know how to fix the bug.

  • I'm willing to submit a PR (Thank you!)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions