From 00adda2cbb3c8fa8c221e5c7cf6700e21d9d78a1 Mon Sep 17 00:00:00 2001 From: Sibiraj Date: Wed, 14 Mar 2018 15:13:56 +0530 Subject: [PATCH] fix: remove disable toolbar on-focus deadcode removed deadcod, inturn notify user with `Range out of Editor` message --- .../common/services/command-executor.service.ts | 4 ++++ src/app/ngx-editor/ngx-editor.component.ts | 13 ++----------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/app/ngx-editor/common/services/command-executor.service.ts b/src/app/ngx-editor/common/services/command-executor.service.ts index ebbec6d4..acb9cce2 100644 --- a/src/app/ngx-editor/common/services/command-executor.service.ts +++ b/src/app/ngx-editor/common/services/command-executor.service.ts @@ -21,6 +21,10 @@ export class CommandExecutorService { */ execute(command: string): void { + if (!this.savedSelection && command !== 'enableObjectResizing') { + throw new Error('Range out of Editor'); + } + if (command === 'enableObjectResizing') { document.execCommand('enableObjectResizing', true, true); return; diff --git a/src/app/ngx-editor/ngx-editor.component.ts b/src/app/ngx-editor/ngx-editor.component.ts index 3f4ab3de..cf781eba 100644 --- a/src/app/ngx-editor/ngx-editor.component.ts +++ b/src/app/ngx-editor/ngx-editor.component.ts @@ -1,7 +1,6 @@ import { - Component, OnInit, Input, Output, - ViewChild, HostListener, ElementRef, EventEmitter, - Renderer2, forwardRef + Component, OnInit, Input, Output, ViewChild, + EventEmitter, Renderer2, forwardRef } from '@angular/core'; import { NG_VALUE_ACCESSOR, ControlValueAccessor } from '@angular/forms'; import * as CodeMirror from 'codemirror'; @@ -96,14 +95,11 @@ export class NgxEditorComponent implements OnInit, ControlValueAccessor { private onTouched: () => void; /** - * - * @param _elementRef api to access dom element * @param _messageService service to send message to the editor message component * @param _commandExecutor executes command from the toolbar * @param _renderer access and manipulate the dom element */ constructor( - private _elementRef: ElementRef, private _messageService: MessageService, private _commandExecutor: CommandExecutorService, private _renderer: Renderer2) { } @@ -112,7 +108,6 @@ export class NgxEditorComponent implements OnInit, ControlValueAccessor { * events */ onTextAreaFocus(): void { - this.enableToolbar = true; this.focus.emit('focus'); return; } @@ -122,10 +117,6 @@ export class NgxEditorComponent implements OnInit, ControlValueAccessor { this.textArea.nativeElement.focus(); } - @HostListener('document:click', ['$event']) onDocumentClick(event: MouseEvent) { - this.enableToolbar = !!this._elementRef.nativeElement.contains(event.target); - } - /** * Executed from the contenteditable section while the input property changes * @param html html string from contenteditable