Skip to content

Commit

Permalink
feat: save file editor content with Ctrl+S
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas committed Jun 2, 2023
1 parent 092d4f0 commit d490a5b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/components/widgets/filesystem/FileEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ export default class FileEditor extends Mixins(BrowserMixin) {
rulers: (this.isMobileViewport) ? [80, 120] : []
})
this.editor.addAction({
id: 'action-save-file',
label: this.$tc('app.general.btn.save'),
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS],
run: () => {
this.$emit('save')
}
})
const filename = this.path ? `${this.path}/${this.filename}` : this.filename
const apiFileUrl = `${this.activeInstance.apiUrl}/server/files/${filename}`
Expand All @@ -126,7 +135,7 @@ export default class FileEditor extends Mixins(BrowserMixin) {
// Focus the editor.
this.$nextTick(() => {
this.editor?.focus()
focus()
})
this.$emit('ready')
Expand All @@ -138,6 +147,10 @@ export default class FileEditor extends Mixins(BrowserMixin) {
})
}
focus () {
this.editor?.focus()
}
showCommandPalette () {
if (this.editor) {
this.editor.focus()
Expand Down
10 changes: 9 additions & 1 deletion src/components/widgets/filesystem/FileEditorDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
:readonly="readonly"
:code-lens="codeLens"
@ready="editorReady = true"
@save="emitSave(false)"
/>

<file-editor-text-only
Expand All @@ -118,7 +119,7 @@
</template>

<script lang="ts">
import { Component, Mixins, Prop, Ref, VModel } from 'vue-property-decorator'
import { Component, Mixins, Prop, Ref, VModel, Watch } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import BrowserMixin from '@/mixins/browser'
import FileEditor from './FileEditor.vue'
Expand Down Expand Up @@ -168,6 +169,13 @@ export default class FileEditorDialog extends Mixins(StateMixin, BrowserMixin) {
)
}
@Watch('ready')
onReady (value: boolean) {
if (value) {
this.editor?.focus()
}
}
get isWebAssemblySupported () {
return isWebAssemblySupported()
}
Expand Down

0 comments on commit d490a5b

Please sign in to comment.