CR fix: setSelection signature and doc change

This commit is contained in:
Meir Rotstein 2018-03-01 23:05:27 +02:00
parent fb85ffdd5b
commit 7e90161057
2 changed files with 19 additions and 19 deletions

View File

@ -376,21 +376,21 @@ Get the current selected nodes, Only applicable for mode 'tree'.
- `{Array<Node>} nodes` - `{Array<Node>} nodes`
#### `JSONEditor.setSelection(node1, node2)` #### `JSONEditor.setSelection(startNode, endNode)`
Set selection for a range of nodes, Only applicable for mode 'tree'. Set selection for a range of nodes, Only applicable for mode 'tree'.
- If no parameters sent - the current selection will be removed, if exists. - 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 - If the nodes are not from the same level the first common parent will be selected
*Parameters:* *Parameters:*
- `{Node} node1` - `{Node} startNode`
Node instance for selection start Node instance for selection start
- `{Node} node2` - `{Node} endNode`
Node instance for selection end Node instance for selection end

View File

@ -1364,26 +1364,26 @@ treemode.onSelectionChange = function (callback) {
* For selecting single node send only the first node parameter * For selecting single node send only the first node parameter
* For clear selection do not send any 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 * 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} [startNode] node for selection start
* @param {Node} [node2] node for selection end * @param {Node} [endNode] node for selection end
*/ */
treemode.setSelection = function (node1, node2) { treemode.setSelection = function (startNode, endNode) {
// check for old usage // 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'); 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 = []; var nodes = [];
if (node1 instanceof Node) { if (startNode instanceof Node) {
if (node2 instanceof Node && node2 !== node1) { if (endNode instanceof Node && endNode !== startNode) {
if (node1.parent === node2.parent) { if (startNode.parent === endNode.parent) {
var start, end; var start, end;
if (node1.getIndex() < node2.getIndex()) { if (startNode.getIndex() < endNode.getIndex()) {
start = node1; start = startNode;
end = node2; end = endNode;
} else { } else {
start = node2; start = endNode;
end = node1; end = startNode;
} }
var current = start; var current = start;
nodes.push(current); nodes.push(current);
@ -1392,10 +1392,10 @@ treemode.setSelection = function (node1, node2) {
nodes.push(current); nodes.push(current);
} while (current && current !== end); } while (current && current !== end);
} else { } else {
nodes = this._findTopLevelNodes(node1, node2); nodes = this._findTopLevelNodes(startNode, endNode);
} }
} else { } else {
nodes.push(node1); nodes.push(startNode);
} }
} }
nodes.forEach(function(node) { nodes.forEach(function(node) {