-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
Description
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
mouseupoutside thetextarea - Firing again when clicking on the selection or beyond the end of the text.
See below for detailed reproduction.
Reproduce the Bug
- Create a simple plugin to listen to the
input-selection-endevent
<!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"
}- Open Logseq, create a block with the text
Something - (Follow the screenshots)
- Select
Somethingand mouse up without leaving the textarea (firing, expected) - Click on the selection (firing, unexpected)
- Same as (i)
- Click beyond the end of the selection (firing, unexpected)
- Select
Somethingand mouse up outside the textarea (not firing, unexpected) - Same as (ii)
- Select
Expected Behavior
- The result should be
- firing
- not firing
- firing
- not firing
- firing
- not firing
Screenshots
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.
logseq/src/main/frontend/ui.cljs
Lines 92 to 102 in 361d08d
| (. 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!)
