From 7e901610570b080ed954bf41687128c6ca383ade Mon Sep 17 00:00:00 2001 From: Meir Rotstein Date: Thu, 1 Mar 2018 23:05:27 +0200 Subject: [PATCH] CR fix: setSelection signature and doc change --- docs/api.md | 8 ++++---- src/js/treemode.js | 30 +++++++++++++++--------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/api.md b/docs/api.md index d1863ba..96e667e 100644 --- a/docs/api.md +++ b/docs/api.md @@ -376,21 +376,21 @@ Get the current selected nodes, Only applicable for mode 'tree'. - `{Array} nodes` -#### `JSONEditor.setSelection(node1, node2)` +#### `JSONEditor.setSelection(startNode, endNode)` Set selection for a range of nodes, Only applicable for mode 'tree'. - If no parameters sent - the current selection will be removed, if exists. -- For single node selecion send a single parameter +- For single node selecion send only the `startNode` parameter. - If the nodes are not from the same level the first common parent will be selected *Parameters:* -- `{Node} node1` +- `{Node} startNode` Node instance for selection start -- `{Node} node2` +- `{Node} endNode` Node instance for selection end diff --git a/src/js/treemode.js b/src/js/treemode.js index 3ac2049..f269c99 100644 --- a/src/js/treemode.js +++ b/src/js/treemode.js @@ -1364,26 +1364,26 @@ treemode.onSelectionChange = function (callback) { * For selecting single node send only the first node parameter * For clear selection do not send any parameter * If the nodes are not from the same level the first common parent will be selected - * @param {Node} [node1] node for selection start - * @param {Node} [node2] node for selection end + * @param {Node} [startNode] node for selection start + * @param {Node} [endNode] node for selection end */ -treemode.setSelection = function (node1, node2) { +treemode.setSelection = function (startNode, endNode) { // check for old usage - if (node1.dom && node1.range) { + if (startNode.dom && startNode.range) { console.warn('setSelection/getSelection usage for text selection is depracated and should not be used, see documantaion for supported selection options'); - this.setDomSelection(node1); + this.setDomSelection(startNode); } var nodes = []; - if (node1 instanceof Node) { - if (node2 instanceof Node && node2 !== node1) { - if (node1.parent === node2.parent) { + if (startNode instanceof Node) { + if (endNode instanceof Node && endNode !== startNode) { + if (startNode.parent === endNode.parent) { var start, end; - if (node1.getIndex() < node2.getIndex()) { - start = node1; - end = node2; + if (startNode.getIndex() < endNode.getIndex()) { + start = startNode; + end = endNode; } else { - start = node2; - end = node1; + start = endNode; + end = startNode; } var current = start; nodes.push(current); @@ -1392,10 +1392,10 @@ treemode.setSelection = function (node1, node2) { nodes.push(current); } while (current && current !== end); } else { - nodes = this._findTopLevelNodes(node1, node2); + nodes = this._findTopLevelNodes(startNode, endNode); } } else { - nodes.push(node1); + nodes.push(startNode); } } nodes.forEach(function(node) {