feat: implemented zoom to fit on code change if previous AST was empty (#3925)
* feat: implemented zoom to fit on code change if previous AST was empty * feat: implementing selectAll text logic to enable select all and copy and paste and zoom to fit will work * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * fix: clarifying comment in _isAstEmpty * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * bump * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * bump again * fix: fixing new type since this branch is old * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: ubuntu-latest-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-latest-8-cores) * bump * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: namespace-profile-ubuntu-8-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-16-cores) * A snapshot a day keeps the bugs away! 📷🐛 (OS: windows-16-cores) --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: 49fl <ircsurfer33@gmail.com>
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 47 KiB |
@ -40,6 +40,7 @@ export const setDiagnosticsEvent = setDiagnosticsAnnotation.of(true)
|
|||||||
export default class EditorManager {
|
export default class EditorManager {
|
||||||
private _copilotEnabled: boolean = true
|
private _copilotEnabled: boolean = true
|
||||||
|
|
||||||
|
private _isAllTextSelected: boolean = false
|
||||||
private _isShiftDown: boolean = false
|
private _isShiftDown: boolean = false
|
||||||
private _selectionRanges: Selections = {
|
private _selectionRanges: Selections = {
|
||||||
otherSelections: [],
|
otherSelections: [],
|
||||||
@ -117,6 +118,10 @@ export default class EditorManager {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get isAllTextSelected() {
|
||||||
|
return this._isAllTextSelected
|
||||||
|
}
|
||||||
|
|
||||||
get editorView(): EditorView | null {
|
get editorView(): EditorView | null {
|
||||||
return this._editorView
|
return this._editorView
|
||||||
}
|
}
|
||||||
@ -362,6 +367,16 @@ export default class EditorManager {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._isAllTextSelected = viewUpdate.state.selection.ranges.some(
|
||||||
|
(selection) => {
|
||||||
|
return (
|
||||||
|
// The user will need to select the empty new lines as well to be considered all of the text.
|
||||||
|
// CTRL+A is the best way to select all the text
|
||||||
|
selection.from === 0 && selection.to === viewUpdate.state.doc.length
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const eventInfo = processCodeMirrorRanges({
|
const eventInfo = processCodeMirrorRanges({
|
||||||
codeMirrorRanges: viewUpdate.state.selection.ranges,
|
codeMirrorRanges: viewUpdate.state.selection.ranges,
|
||||||
selectionRanges: this._selectionRanges,
|
selectionRanges: this._selectionRanges,
|
||||||
|
@ -464,13 +464,42 @@ export class KclManager {
|
|||||||
}
|
}
|
||||||
async executeCode(zoomToFit?: boolean): Promise<void> {
|
async executeCode(zoomToFit?: boolean): Promise<void> {
|
||||||
const ast = await this.safeParse(codeManager.code)
|
const ast = await this.safeParse(codeManager.code)
|
||||||
|
|
||||||
if (!ast) {
|
if (!ast) {
|
||||||
this.clearAst()
|
this.clearAst()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
zoomToFit = this.tryToZoomToFitOnCodeUpdate(ast, zoomToFit)
|
||||||
|
|
||||||
this.ast = { ...ast }
|
this.ast = { ...ast }
|
||||||
return this.executeAst({ zoomToFit })
|
return this.executeAst({ zoomToFit })
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This will override the zoom to fit to zoom into the model if the previous AST was empty.
|
||||||
|
* Workflows this improves,
|
||||||
|
* When someone comments the entire file then uncomments the entire file it zooms to the model
|
||||||
|
* When someone CRTL+A and deletes the code then adds the code back it zooms to the model
|
||||||
|
* When someone CRTL+A and copies new code into the editor it zooms to the model
|
||||||
|
*/
|
||||||
|
tryToZoomToFitOnCodeUpdate(
|
||||||
|
ast: Node<Program>,
|
||||||
|
zoomToFit: boolean | undefined
|
||||||
|
) {
|
||||||
|
const isAstEmpty = this._isAstEmpty(this._ast)
|
||||||
|
const isRequestedAstEmpty = this._isAstEmpty(ast)
|
||||||
|
|
||||||
|
// If the AST went from empty to not empty or
|
||||||
|
// If the user has all of the content selected and they copy new code in
|
||||||
|
if (
|
||||||
|
(isAstEmpty && !isRequestedAstEmpty) ||
|
||||||
|
editorManager.isAllTextSelected
|
||||||
|
) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return zoomToFit
|
||||||
|
}
|
||||||
async format() {
|
async format() {
|
||||||
const originalCode = codeManager.code
|
const originalCode = codeManager.code
|
||||||
const ast = await this.safeParse(originalCode)
|
const ast = await this.safeParse(originalCode)
|
||||||
|