1.0.0 • Published 5 months ago

selection-update v1.0.0

Weekly downloads
9,596
License
MIT
Repository
github
Last release
5 months ago

selection-update

CI

Computing input selection updates on external content changes, as if we used browser managed undo and redo.

API

/**
 * Calculate the selection update for the given
 * current and new input values.
 *
 * @param {Object} currentSelection as {start, end}
 * @param {String} currentValue
 * @param {String} newValue
 *
 * @return {Object} newSelection as {start, end}
 */
calculateUpdate(currentSelection, currentValue, newValue);

Usage

import { calculateUpdate } from 'selection-update';

/**
 * Update input with new value.

 * @param {Node} $input
 * @param {String} newValue
 */
function updateInput($input, newValue) {

  var newSelection;

  // only retrieve and restore input, if the element
  // is currently active
  if (document.activeElement === $input) {

    // get the current selection and pass it in as {start, end}
    newSelection = selectionUpdate(getSelection($input), $input.value, newValue);
  }

  // apply new value, will naturally send selection to input end
  $input.value = value;

  if (newSelection) {
    // set new {start, end} selection on input
    setSelection($input, selection);
  }
}

Related

License

MIT

properties-panel-user-taskvue-bpmn-designer@infinitebrahmanuniverse/nolb-sele@everything-registry/sub-chunk-2728bpmn-vue-middolwom-bpmn-properties-paneltechforce-bpmn-js-properties-paneltechforceai-bpmn-js-properties-paneltf-bpmn-js-properties-panel@dogtiti/dmn-js-sharedethixngonewebcomponentsjc-serve-bpmn-js-properties-panel-activitijc-server-bpmn-js-properties-panel-activitikaka-bpmn-js-properties-paneljp-bpmn-js-properties-paneljc-bpmn-js-properties-panel-activiti@6dtech/6d-bpmn-js-properties-panel@quarks/bpmn-js-properties-panelmy-bpmn-properties-panelnanjids-bpmn-panelrunbpm-js-properties-panelsedsuscipitnisieosphzjhbasicsfr-adapa-bpmn-js-properties-panelsfr-bpmn-js-properties-panelshidl021-bjppifml-jshoutaroy-bpmn-js-properties-panel-activitihi-smart-bpmn-js-properties-panelais-bpmn-js-properties-panelapmn-js-properties-panelcasemanagement-js-properties-panelcms-finance-uicms-fronted-uicms-frontend-uicmmn-js-properties-panelcustom-properties-panelcus-bpmn-js-properties-panelbdframe-workflowbpmn2020bpmn-js-properties-panel-activitibpmn-js-properties-panel-activiti-supportbpmn-js-properties-panel-cnbpmn-js-properties-panel-dz6bpmn-js-properties-panel-for-activitibpmn-js-properties-panel-for-huabibpmn-js-properties-panel-jlbpmn-js-properties-panel-keeleybpmn-js-properties-panel-lswbpmn-js-properties-panel-lzhbpmn-js-properties-panel-select-userbpmn-js-properties-panel-sybpmn-panel-extendbpmn-js-jl-properties-panelbpmn-js-panelbpmn-js-panel-activitibpmn-aranibpmn-domino-properties-panelbpm-micro-bpmn-js-properties-paneldmn-js-sharedenimrecusandaeepx-bpmn-js-properties-paneley-activiti-designerflyme-flow-designgengen-bpmn-panel-activitifugiatcorrupti
1.0.0

5 months ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago