mirror of
https://github.com/heyman/heynote.git
synced 2024-11-27 10:24:14 +01:00
Fix language auto detection on Safari Webkit which was broken
This commit is contained in:
parent
594e23c439
commit
fcf2c630a6
@ -9,6 +9,21 @@ import { LANGUAGE_CHANGE } from "../annotation";
|
|||||||
|
|
||||||
const GUESSLANG_TO_TOKEN = Object.fromEntries(LANGUAGES.map(l => [l.guesslang,l.token]))
|
const GUESSLANG_TO_TOKEN = Object.fromEntries(LANGUAGES.map(l => [l.guesslang,l.token]))
|
||||||
|
|
||||||
|
function requestIdleCallbackCompat(cb) {
|
||||||
|
if (window.requestIdleCallback) {
|
||||||
|
return window.requestIdleCallback(cb)
|
||||||
|
} else {
|
||||||
|
return setTimeout(cb, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelIdleCallbackCompat(id) {
|
||||||
|
if (window.cancelIdleCallback) {
|
||||||
|
window.cancelIdleCallback(id)
|
||||||
|
} else {
|
||||||
|
clearTimeout(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function languageDetection(getView) {
|
export function languageDetection(getView) {
|
||||||
const previousBlockContent = {}
|
const previousBlockContent = {}
|
||||||
@ -45,11 +60,11 @@ export function languageDetection(getView) {
|
|||||||
const plugin = EditorView.updateListener.of(update => {
|
const plugin = EditorView.updateListener.of(update => {
|
||||||
if (update.docChanged) {
|
if (update.docChanged) {
|
||||||
if (idleCallbackId !== null) {
|
if (idleCallbackId !== null) {
|
||||||
cancelIdleCallback(idleCallbackId)
|
cancelIdleCallbackCompat(idleCallbackId)
|
||||||
idleCallbackId = null
|
idleCallbackId = null
|
||||||
}
|
}
|
||||||
|
|
||||||
idleCallbackId = requestIdleCallback(() => {
|
idleCallbackId = requestIdleCallbackCompat(() => {
|
||||||
idleCallbackId = null
|
idleCallbackId = null
|
||||||
|
|
||||||
const range = update.state.selection.asSingle().ranges[0]
|
const range = update.state.selection.asSingle().ranges[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user