enable editor changes in sketch mode, refactor some of the code manager (#2287)
* Revert "Revert "client side sketch updating properly with direct changes to t… (#2286)"
This reverts commit e7ab645267
.
* rejig out side of xstate
* test tweak
* more test tweak
* refactor some codeManager stuff
* tsc
* try and fix tests
* revert small uneeded change
* fix
* snapshot tweak
* more test tweak
* A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu)
* small tweak
* disable bad test
* fmt
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
@ -11,8 +11,7 @@ const PERSIST_CODE_TOKEN = 'persistCode'
|
||||
|
||||
export default class CodeManager {
|
||||
private _code: string = bracket
|
||||
private _updateState: (arg: string) => void = () => {}
|
||||
private _updateEditor: (arg: string) => void = () => {}
|
||||
#updateState: (arg: string) => void = () => {}
|
||||
private _currentFilePath: string | null = null
|
||||
|
||||
constructor() {
|
||||
@ -46,7 +45,7 @@ export default class CodeManager {
|
||||
}
|
||||
|
||||
registerCallBacks({ setCode }: { setCode: (arg: string) => void }) {
|
||||
this._updateState = setCode
|
||||
this.#updateState = setCode
|
||||
}
|
||||
|
||||
updateCurrentFilePath(path: string) {
|
||||
@ -57,18 +56,20 @@ export default class CodeManager {
|
||||
updateCodeState(code: string): void {
|
||||
if (this._code !== code) {
|
||||
this.code = code
|
||||
this._updateState(code)
|
||||
this.#updateState(code)
|
||||
}
|
||||
}
|
||||
|
||||
// Update the code in the editor.
|
||||
updateCodeEditor(code: string): void {
|
||||
const lastCode = this._code
|
||||
this.code = code
|
||||
this._updateEditor(code)
|
||||
if (editorManager.editorView) {
|
||||
editorManager.editorView.dispatch({
|
||||
changes: { from: 0, to: lastCode.length, insert: code },
|
||||
changes: {
|
||||
from: 0,
|
||||
to: editorManager.editorView.state.doc.length,
|
||||
insert: code,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -77,8 +78,7 @@ export default class CodeManager {
|
||||
updateCodeStateEditor(code: string): void {
|
||||
if (this._code !== code) {
|
||||
this.code = code
|
||||
this._updateState(code)
|
||||
this._updateEditor(code)
|
||||
this.#updateState(code)
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user