|
1 | 1 | // Copyright (c) 2025 coze-dev |
2 | 2 | // SPDX-License-Identifier: MIT |
3 | 3 |
|
4 | | -import { FacetCombineStrategy } from '@coze-editor/utils'; |
5 | 4 | import { placeholder as cmPlaceholder } from '@coze-editor/extension-placeholder'; |
6 | | -import { |
7 | | - EditorView, |
8 | | - ViewPlugin, |
9 | | - type ViewUpdate, |
10 | | - lineNumbers as cmLineNumbers, |
11 | | -} from '@codemirror/view'; |
12 | | -import { EditorState, Facet, Prec } from '@codemirror/state'; |
| 5 | +import { EditorView, lineNumbers as cmLineNumbers } from '@codemirror/view'; |
| 6 | +import { EditorState, Prec } from '@codemirror/state'; |
13 | 7 |
|
14 | 8 | export const fontSize = (value?: number) => { |
15 | 9 | if (typeof value === 'undefined') { |
@@ -146,32 +140,3 @@ export const lineNumbers = (enable?: boolean) => |
146 | 140 |
|
147 | 141 | export const lineWrapping = (enable: boolean) => |
148 | 142 | enable ? EditorView.lineWrapping : []; |
149 | | - |
150 | | -const valueFacet = Facet.define<string, string>({ |
151 | | - combine: FacetCombineStrategy.Last, |
152 | | -}); |
153 | | -export const valueExtension = ViewPlugin.fromClass( |
154 | | - class { |
155 | | - update(update: ViewUpdate) { |
156 | | - const currentValue = update.state.doc.toString(); |
157 | | - const newValue = update.state.facet(valueFacet); |
158 | | - |
159 | | - if ( |
160 | | - typeof newValue === 'string' && |
161 | | - newValue && |
162 | | - newValue !== currentValue |
163 | | - ) { |
164 | | - queueMicrotask(() => { |
165 | | - update.view.dispatch({ |
166 | | - changes: { |
167 | | - from: 0, |
168 | | - to: currentValue.length, |
169 | | - insert: newValue, |
170 | | - }, |
171 | | - }); |
172 | | - }); |
173 | | - } |
174 | | - } |
175 | | - }, |
176 | | -); |
177 | | -export const value = (v: string) => valueFacet.of(v); |
0 commit comments