mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Remove findEffect (#16343)
GitOrigin-RevId: b8472f5128deac5e7f94fb1ec1e64899a8da510a
This commit is contained in:
parent
dc962832f0
commit
8feef7bf5e
2 changed files with 11 additions and 12 deletions
|
@ -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,10 +83,11 @@ 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
|
||||||
|
|
|
@ -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))
|
|
||||||
|
|
Loading…
Reference in a new issue