Double click to edit, double escape to stop
This commit is contained in:
parent
6bcb4bf455
commit
5983e56d11
@ -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"
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@ -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>
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user