Prevent generating with no context,

This commit is contained in:
turboderp
2023-11-18 08:57:05 +01:00
parent fd94fc6f82
commit 115f6c2abe

View File

@@ -417,14 +417,16 @@ class NotepadView {
generateToken() {
if (!globals.g.loadedModelUUID) return;
this.generateButton.setEnabled(false, 200);
this.generateTokenButton.setEnabled(false, 200);
this.editor.disabled = true;
let pos = this.editor.selectionStart;
let end = this.editor.selectionEnd;
let text = this.editor.value;
if (pos == 0) return;
this.generateButton.setEnabled(false, 200);
this.generateTokenButton.setEnabled(false, 200);
this.editor.disabled = true;
if (end > pos) {
this.editor.value = this.editor.value.slice(0, pos) + this.editor.value.slice(end);
}
@@ -455,6 +457,12 @@ class NotepadView {
generate() {
if (!globals.g.loadedModelUUID) return;
let pos = this.editor.selectionStart;
let end = this.editor.selectionEnd;
let text = this.editor.value;
if (pos == 0) return;
this.generateButton.setEnabled(false);
this.generateButton.setVisible(false);
this.cancelButton.setEnabled(true);
@@ -462,10 +470,6 @@ class NotepadView {
this.generateTokenButton.setEnabled(false);
this.editor.disabled = true;
let pos = this.editor.selectionStart;
let end = this.editor.selectionEnd;
let text = this.editor.value;
if (end > pos) {
this.editor.value = this.editor.value.slice(0, pos) + this.editor.value.slice(end);
}