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 { visualKeymap } from './visual-keymap'
import { mousedown, mouseDownEffect } from './selection'
import { findEffect } from '../../utils/effects'
import { forceParsing, syntaxTree } from '@codemirror/language'
import { hasLanguageLoadedEffect } from '../language'
import { restoreScrollPosition } from '../scroll-position'
@ -34,14 +33,18 @@ type Options = {
const visualConf = new Compartment()
export const toggleVisualEffect = StateEffect.define<boolean>()
export const findToggleVisualEffect = findEffect(toggleVisualEffect)
const visualState = StateField.define<boolean>({
create() {
return false
},
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
EditorState.transactionExtender.of(tr => {
const effect = findToggleVisualEffect(tr)
if (effect) {
for (const effect of tr.effects) {
if (effect.is(toggleVisualEffect)) {
return {
effects: conf.reconfigure(configure(effect.value)),
}
}
}
return null
}),

View file

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