Skip to content

Commit

Permalink
CR fix - remove 'Node' from node selection function signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
meirotstein committed Mar 1, 2018
1 parent 8cbe15a commit fb85ffd
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 50 deletions.
8 changes: 4 additions & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Constructs a new JSONEditor.
```
Only applicable when `mode` is 'code' or 'text'.

- `{function} onNodeSelectionChange`
- `{function} onSelectionChange`

Set a callback function triggered when Nodes are selected in the JSONEditor.

Expand All @@ -218,7 +218,7 @@ Constructs a new JSONEditor.
/**
* @param {Array<Node>} nodes selected nodes
*/
function onNodeSelectionChange(nodes) {
function onSelectionChange(nodes) {
...
}
```
Expand Down Expand Up @@ -368,15 +368,15 @@ Set text selection for a range, Only applicable for mode 'text' and 'code'.

Position for selection end

#### `JSONEditor.getNodeSelection()`
#### `JSONEditor.getSelection()`

Get the current selected nodes, Only applicable for mode 'tree'.

*Returns:*

- `{Array<Node>} nodes`

#### `JSONEditor.setNodeSelection(node1, node2)`
#### `JSONEditor.setSelection(node1, node2)`

Set selection for a range of nodes, Only applicable for mode 'tree'.

Expand Down
6 changes: 3 additions & 3 deletions examples/14_selection_api.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
editor.getTextSelection()
editor.setTextSelection(startPos,endPos)
// tree mode:
editor.getNodeSelection()
editor.setNodeSelection(Node1,Node2)
editor.getSelection()
editor.setSelection(Node1,Node2)
</code>
</p>

Expand Down Expand Up @@ -91,7 +91,7 @@
var textEl = document.getElementById('selectedText');
textEl.innerHTML = text;
},
onNodeSelectionChange: function(nodes) {
onSelectionChange: function(nodes) {
var nodesEl = document.getElementById('selectedNodes');
var nodesCountEl = document.getElementById('selectedCount');
nodesCountEl.innerHTML = nodes.length + ' nodes selected';
Expand Down
4 changes: 2 additions & 2 deletions src/js/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ History.prototype.undo = function () {
if (action && action.undo) {
action.undo(obj.params);
if (obj.params.oldSelection) {
this.editor.setSelection(obj.params.oldSelection);
this.editor.setDomSelection(obj.params.oldSelection);
}
}
else {
Expand All @@ -241,7 +241,7 @@ History.prototype.redo = function () {
if (action && action.redo) {
action.redo(obj.params);
if (obj.params.newSelection) {
this.editor.setSelection(obj.params.newSelection);
this.editor.setDomSelection(obj.params.newSelection);
}
}
else {
Expand Down
10 changes: 5 additions & 5 deletions src/js/JSONEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ var util = require('./util');
* {boolean} sortObjectKeys If true, object keys are
* sorted before display.
* false by default.
* {function} onNodeSelectionChange Callback method,
* triggered on node selection change
* Only applicable for modes
* 'tree', 'view', and 'form'
* {function} onSelectionChange Callback method,
* triggered on node selection change
* Only applicable for modes
* 'tree', 'view', and 'form'
* {function} onTextSelectionChange Callback method,
* triggered on text selection change
* Only applicable for modes
Expand Down Expand Up @@ -89,7 +89,7 @@ function JSONEditor (container, options, json) {
var VALID_OPTIONS = [
'ajv', 'schema', 'schemaRefs','templates',
'ace', 'theme','autocomplete',
'onChange', 'onEditable', 'onError', 'onModeChange', 'onNodeSelectionChange', 'onTextSelectionChange',
'onChange', 'onEditable', 'onError', 'onModeChange', 'onSelectionChange', 'onTextSelectionChange',
'escapeUnicode', 'history', 'search', 'mode', 'modes', 'name', 'indentation',
'sortObjectKeys', 'navigationBar', 'statusBar'
];
Expand Down
56 changes: 28 additions & 28 deletions src/js/Node.js
Original file line number Diff line number Diff line change
Expand Up @@ -1164,13 +1164,13 @@ Node.prototype._getDomValue = function(silent) {
Node.prototype._onChangeValue = function () {
// get current selection, then override the range such that we can select
// the added/removed text on undo/redo
var oldSelection = this.editor.getSelection();
var oldSelection = this.editor.getDomSelection();
if (oldSelection.range) {
var undoDiff = util.textDiff(String(this.value), String(this.previousValue));
oldSelection.range.startOffset = undoDiff.start;
oldSelection.range.endOffset = undoDiff.end;
}
var newSelection = this.editor.getSelection();
var newSelection = this.editor.getDomSelection();
if (newSelection.range) {
var redoDiff = util.textDiff(String(this.previousValue), String(this.value));
newSelection.range.startOffset = redoDiff.start;
Expand All @@ -1195,13 +1195,13 @@ Node.prototype._onChangeValue = function () {
Node.prototype._onChangeField = function () {
// get current selection, then override the range such that we can select
// the added/removed text on undo/redo
var oldSelection = this.editor.getSelection();
var oldSelection = this.editor.getDomSelection();
if (oldSelection.range) {
var undoDiff = util.textDiff(this.field, this.previousField);
oldSelection.range.startOffset = undoDiff.start;
oldSelection.range.endOffset = undoDiff.end;
}
var newSelection = this.editor.getSelection();
var newSelection = this.editor.getDomSelection();
if (newSelection.range) {
var redoDiff = util.textDiff(this.previousField, this.field);
newSelection.range.startOffset = redoDiff.start;
Expand Down Expand Up @@ -1573,7 +1573,7 @@ Node.onDragStart = function (nodes, event) {
editor.highlighter.lock();
editor.drag = {
oldCursor: document.body.style.cursor,
oldSelection: editor.getSelection(),
oldSelection: editor.getDomSelection(),
oldBeforeNode: beforeNode,
mouseX: event.pageX,
offsetY: offsetY,
Expand Down Expand Up @@ -1771,7 +1771,7 @@ Node.onDragEnd = function (nodes, event) {
var params = {
nodes: nodes,
oldSelection: editor.drag.oldSelection,
newSelection: editor.getSelection(),
newSelection: editor.getDomSelection(),
oldBeforeNode: editor.drag.oldBeforeNode,
newBeforeNode: beforeNode
};
Expand Down Expand Up @@ -2323,7 +2323,7 @@ Node.prototype.onEvent = function (event) {
case 'keydown':
case 'mousedown':
// TODO: cleanup
this.editor.selection = this.editor.getSelection();
this.editor.selection = this.editor.getDomSelection();
break;

case 'click':
Expand Down Expand Up @@ -2374,7 +2374,7 @@ Node.prototype.onEvent = function (event) {

case 'keydown':
case 'mousedown':
this.editor.selection = this.editor.getSelection();
this.editor.selection = this.editor.getDomSelection();
break;

case 'keyup':
Expand Down Expand Up @@ -2549,7 +2549,7 @@ Node.prototype.onKeyDown = function (event) {
if (nextNode && nextNode instanceof AppendNode &&
!(lastNode.parent.childs.length == 1) &&
nextNode2 && nextNode2.parent) {
oldSelection = this.editor.getSelection();
oldSelection = this.editor.getDomSelection();
oldBeforeNode = lastNode.nextSibling();

selectedNodes.forEach(function (node) {
Expand All @@ -2562,7 +2562,7 @@ Node.prototype.onKeyDown = function (event) {
oldBeforeNode: oldBeforeNode,
newBeforeNode: nextNode2,
oldSelection: oldSelection,
newSelection: this.editor.getSelection()
newSelection: this.editor.getDomSelection()
});
}
}
Expand Down Expand Up @@ -2596,7 +2596,7 @@ Node.prototype.onKeyDown = function (event) {
// find the previous node
prevNode = firstNode._previousNode();
if (prevNode && prevNode.parent) {
oldSelection = this.editor.getSelection();
oldSelection = this.editor.getDomSelection();
oldBeforeNode = lastNode.nextSibling();

selectedNodes.forEach(function (node) {
Expand All @@ -2609,7 +2609,7 @@ Node.prototype.onKeyDown = function (event) {
oldBeforeNode: oldBeforeNode,
newBeforeNode: prevNode,
oldSelection: oldSelection,
newSelection: this.editor.getSelection()
newSelection: this.editor.getDomSelection()
});
}
handled = true;
Expand All @@ -2632,7 +2632,7 @@ Node.prototype.onKeyDown = function (event) {
if (prevNode && prevNode.parent &&
(prevNode instanceof AppendNode)
&& !prevNode.isVisible()) {
oldSelection = this.editor.getSelection();
oldSelection = this.editor.getDomSelection();
oldBeforeNode = lastNode.nextSibling();

selectedNodes.forEach(function (node) {
Expand All @@ -2645,7 +2645,7 @@ Node.prototype.onKeyDown = function (event) {
oldBeforeNode: oldBeforeNode,
newBeforeNode: prevNode,
oldSelection: oldSelection,
newSelection: this.editor.getSelection()
newSelection: this.editor.getDomSelection()
});
}
}
Expand Down Expand Up @@ -2685,7 +2685,7 @@ Node.prototype.onKeyDown = function (event) {
}
var nextNode2 = nextNode && (nextNode._nextNode() || nextNode.parent.append);
if (nextNode2 && nextNode2.parent) {
oldSelection = this.editor.getSelection();
oldSelection = this.editor.getDomSelection();
oldBeforeNode = lastNode.nextSibling();

selectedNodes.forEach(function (node) {
Expand All @@ -2698,7 +2698,7 @@ Node.prototype.onKeyDown = function (event) {
oldBeforeNode: oldBeforeNode,
newBeforeNode: nextNode2,
oldSelection: oldSelection,
newSelection: this.editor.getSelection()
newSelection: this.editor.getDomSelection()
});
}
handled = true;
Expand Down Expand Up @@ -2756,9 +2756,9 @@ Node.onRemove = function(nodes) {
editor.highlighter.unhighlight();

// adjust the focus
var oldSelection = editor.getSelection();
var oldSelection = editor.getDomSelection();
Node.blurNodes(nodes);
var newSelection = editor.getSelection();
var newSelection = editor.getDomSelection();

// remove the nodes
nodes.forEach(function (node) {
Expand Down Expand Up @@ -2795,7 +2795,7 @@ Node.onDuplicate = function(nodes) {
editor.deselect(editor.multiselection.nodes);

// duplicate the nodes
var oldSelection = editor.getSelection();
var oldSelection = editor.getDomSelection();
var afterNode = lastNode;
var clones = nodes.map(function (node) {
var clone = node.clone();
Expand All @@ -2811,7 +2811,7 @@ Node.onDuplicate = function(nodes) {
else {
editor.select(clones);
}
var newSelection = editor.getSelection();
var newSelection = editor.getDomSelection();

editor._onAction('duplicateNodes', {
afterNode: lastNode,
Expand All @@ -2831,7 +2831,7 @@ Node.onDuplicate = function(nodes) {
* @private
*/
Node.prototype._onInsertBefore = function (field, value, type) {
var oldSelection = this.editor.getSelection();
var oldSelection = this.editor.getDomSelection();

var newNode = new Node(this.editor, {
field: (field != undefined) ? field : '',
Expand All @@ -2842,7 +2842,7 @@ Node.prototype._onInsertBefore = function (field, value, type) {
this.parent.insertBefore(newNode, this);
this.editor.highlighter.unhighlight();
newNode.focus('field');
var newSelection = this.editor.getSelection();
var newSelection = this.editor.getDomSelection();

this.editor._onAction('insertBeforeNodes', {
nodes: [newNode],
Expand All @@ -2861,7 +2861,7 @@ Node.prototype._onInsertBefore = function (field, value, type) {
* @private
*/
Node.prototype._onInsertAfter = function (field, value, type) {
var oldSelection = this.editor.getSelection();
var oldSelection = this.editor.getDomSelection();

var newNode = new Node(this.editor, {
field: (field != undefined) ? field : '',
Expand All @@ -2872,7 +2872,7 @@ Node.prototype._onInsertAfter = function (field, value, type) {
this.parent.insertAfter(newNode, this);
this.editor.highlighter.unhighlight();
newNode.focus('field');
var newSelection = this.editor.getSelection();
var newSelection = this.editor.getDomSelection();

this.editor._onAction('insertAfterNodes', {
nodes: [newNode],
Expand All @@ -2891,7 +2891,7 @@ Node.prototype._onInsertAfter = function (field, value, type) {
* @private
*/
Node.prototype._onAppend = function (field, value, type) {
var oldSelection = this.editor.getSelection();
var oldSelection = this.editor.getDomSelection();

var newNode = new Node(this.editor, {
field: (field != undefined) ? field : '',
Expand All @@ -2902,7 +2902,7 @@ Node.prototype._onAppend = function (field, value, type) {
this.parent.appendChild(newNode);
this.editor.highlighter.unhighlight();
newNode.focus('field');
var newSelection = this.editor.getSelection();
var newSelection = this.editor.getDomSelection();

this.editor._onAction('appendNodes', {
nodes: [newNode],
Expand All @@ -2920,9 +2920,9 @@ Node.prototype._onAppend = function (field, value, type) {
Node.prototype._onChangeType = function (newType) {
var oldType = this.type;
if (newType != oldType) {
var oldSelection = this.editor.getSelection();
var oldSelection = this.editor.getDomSelection();
this.changeType(newType);
var newSelection = this.editor.getSelection();
var newSelection = this.editor.getDomSelection();

this.editor._onAction('changeType', {
node: this,
Expand Down
Loading

0 comments on commit fb85ffd

Please sign in to comment.