Remove findEffect (#16343)

GitOrigin-RevId: b8472f5128deac5e7f94fb1ec1e64899a8da510a
This commit is contained in:
Alf Eaton 2024-01-03 12:40:19 +00:00 committed by Copybot
parent dc962832f0
commit 8feef7bf5e
2 changed files with 11 additions and 12 deletions

View file

@ -12,7 +12,6 @@ import { markDecorations } from './mark-decorations'
import { EditorView, ViewPlugin } from '@codemirror/view' import { EditorView, ViewPlugin } from '@codemirror/view'
import { visualKeymap } from './visual-keymap' import { visualKeymap } from './visual-keymap'
import { mousedown, mouseDownEffect } from './selection' import { mousedown, mouseDownEffect } from './selection'
import { findEffect } from '../../utils/effects'
import { forceParsing, syntaxTree } from '@codemirror/language' import { forceParsing, syntaxTree } from '@codemirror/language'
import { hasLanguageLoadedEffect } from '../language' import { hasLanguageLoadedEffect } from '../language'
import { restoreScrollPosition } from '../scroll-position' import { restoreScrollPosition } from '../scroll-position'
@ -34,14 +33,18 @@ type Options = {
const visualConf = new Compartment() const visualConf = new Compartment()
export const toggleVisualEffect = StateEffect.define<boolean>() export const toggleVisualEffect = StateEffect.define<boolean>()
export const findToggleVisualEffect = findEffect(toggleVisualEffect)
const visualState = StateField.define<boolean>({ const visualState = StateField.define<boolean>({
create() { create() {
return false return false
}, },
update(value, tr) { update(value, tr) {
return findToggleVisualEffect(tr)?.value ?? value for (const effect of tr.effects) {
if (effect.is(toggleVisualEffect)) {
return effect.value
}
}
return value
}, },
}) })
@ -80,12 +83,13 @@ export const sourceOnly = (visual: boolean, extension: Extension) => {
// Respond to switching editor modes // Respond to switching editor modes
EditorState.transactionExtender.of(tr => { EditorState.transactionExtender.of(tr => {
const effect = findToggleVisualEffect(tr) for (const effect of tr.effects) {
if (effect) { if (effect.is(toggleVisualEffect)) {
return { return {
effects: conf.reconfigure(configure(effect.value)), effects: conf.reconfigure(configure(effect.value)),
} }
} }
}
return null return null
}), }),

View file

@ -12,8 +12,3 @@ export const updateHasEffect =
update.transactions.some(tr => update.transactions.some(tr =>
tr.effects.some(effect => effect.is(effectType)) tr.effects.some(effect => effect.is(effectType))
) )
export const findEffect =
<T>(effectType: StateEffectType<T>) =>
(tr: Transaction) =>
tr.effects.find(effect => effect.is(effectType))