Require confirmation for quitting a 'dirty' document
This commit is contained in:
parent
b665ce8ce7
commit
5cd59ba943
@ -74,6 +74,8 @@ export class Document {
|
|||||||
|
|
||||||
row.delete(at.x);
|
row.delete(at.x);
|
||||||
row.updateRender();
|
row.updateRender();
|
||||||
|
|
||||||
|
this.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public row(i: number): Row | null {
|
public row(i: number): Row | null {
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
import Ansi, { KeyCommand } from './ansi.ts';
|
import Ansi, { KeyCommand } from './ansi.ts';
|
||||||
import Buffer from './buffer.ts';
|
import Buffer from './buffer.ts';
|
||||||
import Document from './document.ts';
|
import Document from './document.ts';
|
||||||
import { ITerminalSize, logToFile, Position, SCROLL_VERSION } from './mod.ts';
|
import {
|
||||||
|
ITerminalSize,
|
||||||
|
logToFile,
|
||||||
|
Position,
|
||||||
|
SCROLL_QUIT_TIMES,
|
||||||
|
SCROLL_VERSION,
|
||||||
|
} from './mod.ts';
|
||||||
import Row from './row.ts';
|
import Row from './row.ts';
|
||||||
import { ctrlKey, maxAdd, posSub, truncate } from './utils.ts';
|
import { ctrlKey, maxAdd, posSub, truncate } from './utils.ts';
|
||||||
|
|
||||||
@ -50,6 +56,11 @@ class Editor {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
#statusTimeout: number = 0;
|
#statusTimeout: number = 0;
|
||||||
|
/**
|
||||||
|
* The number of times required to quit a dirty document
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
#quitTimes: number = SCROLL_QUIT_TIMES;
|
||||||
|
|
||||||
constructor(terminalSize: ITerminalSize) {
|
constructor(terminalSize: ITerminalSize) {
|
||||||
this.#buffer = new Buffer();
|
this.#buffer = new Buffer();
|
||||||
@ -95,6 +106,14 @@ class Editor {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ctrlKey('q'):
|
case ctrlKey('q'):
|
||||||
|
if (this.#quitTimes > 0 && this.#document.dirty) {
|
||||||
|
this.setStatusMessage(
|
||||||
|
'WARNING!!! File has unsaved changes. ' +
|
||||||
|
`Press Ctrl-Q ${this.#quitTimes} more times to quit.`,
|
||||||
|
);
|
||||||
|
this.#quitTimes--;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
await this.clearScreen();
|
await this.clearScreen();
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -165,6 +184,11 @@ class Editor {
|
|||||||
this.#cursor.x++;
|
this.#cursor.x++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.#quitTimes < SCROLL_QUIT_TIMES) {
|
||||||
|
this.#quitTimes = SCROLL_QUIT_TIMES;
|
||||||
|
this.setStatusMessage('');
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,7 +39,13 @@ const DenoFFI: IFFI = {
|
|||||||
tcsetattr,
|
tcsetattr,
|
||||||
cfmakeraw,
|
cfmakeraw,
|
||||||
getPointer: Deno.UnsafePointer.of,
|
getPointer: Deno.UnsafePointer.of,
|
||||||
close: cStdLib.close,
|
close: () => {
|
||||||
|
try {
|
||||||
|
cStdLib.close();
|
||||||
|
} catch {
|
||||||
|
// The error thrown is annoying, but harmless.
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default DenoFFI;
|
export default DenoFFI;
|
||||||
|
Loading…
Reference in New Issue
Block a user