Skip to content

Commit b4a5a02

Browse files
committed
Work around broken focus/preventScroll support in Safari 26
FIX: Work around an issue in Safari 26 that causes inappropriate scrolling on focus in some circumstances. Closes codemirror/dev#1626
1 parent 45268f0 commit b4a5a02

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/browser.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export default {
2424
ios,
2525
android: /Android\b/.test(nav.userAgent),
2626
webkit,
27-
safari,
2827
webkit_version: webkit ? +(/\bAppleWebKit\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
28+
safari,
29+
safari_version: safari ? +(/\bVersion\/(\d+(\.\d+)?)/.exec(nav.userAgent) || [0, 0])[1] : 0,
2930
tabSize: doc.documentElement.style.tabSize != null ? "tab-size" : "-moz-tab-size"
3031
}

src/dom.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import browser from "./browser"
2+
13
export function getSelection(root: DocumentOrShadowRoot): Selection | null {
24
let target
35
// Browsers differ on whether shadow roots have a getSelection
@@ -254,6 +256,8 @@ export class DOMSelectionState implements SelectionRange {
254256
}
255257

256258
let preventScrollSupported: null | false | {preventScroll: boolean} = null
259+
// Safari 26 breaks preventScroll support
260+
if (browser.safari && browser.safari_version >= 26) preventScrollSupported = false
257261
// Feature-detects support for .focus({preventScroll: true}), and uses
258262
// a fallback kludge when not supported.
259263
export function focusPreventScroll(dom: HTMLElement) {

0 commit comments

Comments
 (0)