Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix composer touch bar flickering on keypress in Chrome #4173

Merged
merged 1 commit into from
Mar 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/editor/caret.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,27 @@ function setDocumentRangeSelection(editor, model, range) {
}

export function setCaretPosition(editor, model, caretPosition) {
const sel = document.getSelection();
sel.removeAllRanges();
const range = document.createRange();
const {node, offset} = getNodeAndOffsetForPosition(editor, model, caretPosition);
range.setStart(node, offset);
range.collapse(true);

const sel = document.getSelection();
if (sel.rangeCount === 1) {
const existingRange = sel.getRangeAt(0);
if (
existingRange.startContainer === range.startContainer &&
existingRange.startOffset === range.startOffset &&
existingRange.collapsed === range.collapsed
) {
// If the selection matches, it's important to leave it alone.
// Recreating the selection state in at least Chrome can cause
// strange side effects, like touch bar flickering on every key.
// See https://github.com/vector-im/riot-web/issues/9299
return;
}
}
sel.removeAllRanges();
sel.addRange(range);
}

Expand Down