Skip to content

Commit

Permalink
Fix macOS double-space-period suppression on Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jan 9, 2025
1 parent 3dca895 commit 26af8ea
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/domchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export function applyDOMChange(view: EditorView, domChange: DOMChange): boolean
if (!change && domChange.typeOver && !sel.empty && newSel && newSel.main.empty) {
// Heuristic to notice typing over a selected character
change = {from: sel.from, to: sel.to, insert: view.state.doc.slice(sel.from, sel.to)}
} else if ((browser.mac || browser.android) && change && change.from == change.to && change.from == sel.head - 1 &&
/^\. ?$/.test(change.insert.toString()) && view.contentDOM.getAttribute("autocorrect") == "off") {
// Detect insert-period-on-double-space Mac and Android behavior,
// and transform it into a regular space insert.
if (newSel && change.insert.length == 2) newSel = EditorSelection.single(newSel.main.anchor - 1, newSel.main.head - 1)
change = {from: change.from, to: change.to, insert: Text.of([change.insert.toString().replace(".", " ")])}
} else if (change && change.from >= sel.from && change.to <= sel.to &&
(change.from != sel.from || change.to != sel.to) &&
(sel.to - sel.from) - (change.to - change.from) <= 4) {
Expand All @@ -102,12 +108,6 @@ export function applyDOMChange(view: EditorView, domChange: DOMChange): boolean
from: sel.from, to: sel.to,
insert: view.state.doc.slice(sel.from, change.from).append(change.insert).append(view.state.doc.slice(change.to, sel.to))
}
} else if ((browser.mac || browser.android) && change && change.from == change.to && change.from == sel.head - 1 &&
/^\. ?$/.test(change.insert.toString()) && view.contentDOM.getAttribute("autocorrect") == "off") {
// Detect insert-period-on-double-space Mac and Android behavior,
// and transform it into a regular space insert.
if (newSel && change.insert.length == 2) newSel = EditorSelection.single(newSel.main.anchor - 1, newSel.main.head - 1)
change = {from: sel.from, to: sel.to, insert: Text.of([" "])}
} else if (browser.chrome && change && change.from == change.to && change.from == sel.head &&
change.insert.toString() == "\n " && view.lineWrapping) {
// In Chrome, if you insert a space at the start of a wrapped
Expand Down

0 comments on commit 26af8ea

Please sign in to comment.