diff --git a/core/client.js b/core/client.js index 78dfd4de..602bd3b7 100644 --- a/core/client.js +++ b/core/client.js @@ -149,12 +149,14 @@ class TfFilesElement extends LitElement { return { current: {type: String}, files: {type: Object}, + dropping: {type: Number}, }; } constructor() { super(); this.files = {}; + this.dropping = 0; } file_click(file) { @@ -178,6 +180,36 @@ class TfFilesElement extends LitElement { return html`
this.file_click(file)}>${file}
`; } + async drop(event) { + event.preventDefault(); + event.stopPropagation(); + this.dropping = 0; + for (let file of event.dataTransfer.files) { + let text = ''; + try { + text = await file.text(); + } catch { + text = new TextDecoder('latin1').decode(await file.arrayBuffer()); + } + gFiles[file.name] = { + doc: new CodeMirror.Doc(text, guessMode(file.name)), + generation: -1, + }; + gCurrentFile = file.name; + } + openFile(gCurrentFile); + updateFiles(); + } + + drag_enter(event) { + this.dropping++; + event.preventDefault(); + } + + drag_leave(event) { + this.dropping--; + } + render() { let self = this; return html` @@ -202,9 +234,15 @@ class TfFilesElement extends LitElement { content: '*'; } -
+
${Object.keys(this.files).sort().map(x => self.render_file(x))}
+
+ Drop File(s) +
`; } } @@ -992,7 +1030,6 @@ function updateFiles() { }])); files.current = gCurrentFile; } - gEditor.focus(); }