[26194] Skip activation of edit field with active selection within (#5885)

https://community.openproject.com/wp/26194

[ci skip]
pull/5889/head
Oliver Günther 7 years ago committed by GitHub
parent 48f8589087
commit f405d68f73
  1. 10
      frontend/app/components/wp-edit/wp-edit-field/wp-edit-field.directive.ts
  2. 21
      frontend/app/helpers/selection-helpers.ts

@ -44,6 +44,8 @@ import {WorkPackageEditFieldGroupController} from './wp-edit-field-group.directi
import {ClickPositionMapper} from '../../common/set-click-position/set-click-position';
import {WorkPackageEditFieldHandler} from '../../wp-edit-form/work-package-edit-field-handler';
import {WorkPackageEditingService} from '../../wp-edit-form/work-package-editing-service';
import {SelectionHelpers} from '../../../helpers/selection-helpers';
import {debugLog} from '../../../helpers/debug_output';
export class WorkPackageEditFieldController {
public wpEditFieldGroup:WorkPackageEditFieldGroupController;
@ -103,12 +105,20 @@ export class WorkPackageEditFieldController {
}
public activateIfEditable(event:JQueryEventObject) {
// Ignore selections
if (SelectionHelpers.hasSelectionWithin(event.target)) {
debugLog(`Not activating ${this.fieldName} because of active selection within`);
return true;
}
if (this.isEditable) {
this.handleUserActivate(event);
}
this.contextMenu.close();
event.stopImmediatePropagation();
return false;
}
public activate(noWarnings:boolean = false):Promise<WorkPackageEditFieldHandler> {

@ -0,0 +1,21 @@
export namespace SelectionHelpers {
/**
* Test whether we currently have a selection within.
* @param {HTMLElement} target
* @return {boolean}
*/
export function hasSelectionWithin(target:Element):boolean {
try {
const selection = window.getSelection();
const hasSelection = selection.toString().length > 0;
const isWithin = target.contains(getSelection().anchorNode);
return hasSelection && isWithin;
} catch (e) {
console.error('Failed to test whether in selection ' + e);
return false;
}
}
}
Loading…
Cancel
Save