Double click to edit, double escape to stop
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing

This commit is contained in:
Garrett Mills 2020-10-28 09:02:36 -05:00
parent 6bcb4bf455
commit 5983e56d11
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
4 changed files with 32 additions and 8 deletions

View File

@ -1,4 +1,4 @@
<div class="container" (click)="onFocusIn()"> <div class="container" (dblclick)="onFocusIn()">
<div class="editor-container" *ngIf="showEditor"> <div class="editor-container" *ngIf="showEditor">
<ngx-monaco-editor class="editor" <ngx-monaco-editor class="editor"
[options]="editorOptions" [options]="editorOptions"

View File

@ -18,6 +18,7 @@ export class MarkdownComponent extends EditorNodeContract implements OnInit {
public contents = ''; public contents = '';
private dirtyOverride = false; private dirtyOverride = false;
public showEditor = false; public showEditor = false;
protected hadOneFocusOut = false;
public editorOptions = { public editorOptions = {
language: 'markdown', language: 'markdown',
@ -73,6 +74,14 @@ export class MarkdownComponent extends EditorNodeContract implements OnInit {
@HostListener('document:keyup.escape', ['$event']) @HostListener('document:keyup.escape', ['$event'])
onFocusOut(event) { onFocusOut(event) {
if ( !this.hadOneFocusOut ) {
this.hadOneFocusOut = true;
setTimeout(() => {
this.hadOneFocusOut = false;
}, 500);
} else {
this.hadOneFocusOut = false;
this.showEditor = false; this.showEditor = false;
} }
}
} }

View File

@ -1,5 +1,5 @@
<div class="container" <div class="container"
(focusin)="onFocusIn($event)"> (dblclick)="onFocusIn($event)">
<div class="toolbar-base" *ngIf="isFocused"> <div class="toolbar-base" *ngIf="isFocused">
<button class="toolbar-button" title="Bold" (click)="documentCommand('bold')"> <button class="toolbar-button" title="Bold" (click)="documentCommand('bold')">
<i class="icon fa fa-bold"></i> <i class="icon fa fa-bold"></i>
@ -70,8 +70,14 @@
[ngClass]="isFocused ? 'focused' : ''" [ngClass]="isFocused ? 'focused' : ''"
contenteditable contenteditable
appDomChange appDomChange
*ngIf="isFocused"
[innerHTML]="initialValue" [innerHTML]="initialValue"
#editable #editable
(domChange)="onContentsChanged($event)" (domChange)="onContentsChanged($event)"
></div> ></div>
<div
class="editable-base"
*ngIf="!isFocused"
[innerHTML]="initialValue"
></div>
</div> </div>

View File

@ -16,6 +16,7 @@ export class NormComponent extends EditorNodeContract implements OnInit {
protected savedValue = 'Click to edit...'; protected savedValue = 'Click to edit...';
public contents = ''; public contents = '';
private dirtyOverride = false; private dirtyOverride = false;
protected hadOneFocusOut = false;
constructor( constructor(
public readonly editorService: EditorService, public readonly editorService: EditorService,
@ -55,7 +56,15 @@ export class NormComponent extends EditorNodeContract implements OnInit {
@HostListener('document:keyup.escape', ['$event']) @HostListener('document:keyup.escape', ['$event'])
onFocusOut(event) { onFocusOut(event) {
if ( !this.hadOneFocusOut ) {
this.hadOneFocusOut = true;
setTimeout(() => {
this.hadOneFocusOut = false;
}, 500);
} else {
this.isFocused = false; this.isFocused = false;
this.hadOneFocusOut = false;
}
} }
documentCommand(cmd: string) { documentCommand(cmd: string) {