This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Refactor remotefunctions #1529
Merged
Merged
Refactor remotefunctions #1529
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
773c785
started refactoring the remote functions
a57b594
Merge branch 'master-up' into refactor-remotefunctions
4f5c2e2
Merge branch 'live-development' into refactor-remotefunctions
c71b221
done refactoring
f3517f1
Merge branch 'live-development' into refactor-remotefunctions
f39cee0
For LiveDevelopment errors: Remove the prefix "Uncaught" to prevent t…
DennisKehrig 577ecac
Merge branch 'live-development' of https://github.com/DennisKehrig/br…
a34f467
Revert "For LiveDevelopment errors: Remove the prefix "Uncaught" to p…
22146bb
Merge branch 'live-development' into refactor-remotefunctions
95a31cf
Merge branch 'master-up' into refactor-remotefunctions
7512f7a
some minor bug fixes on the highlighting and menu
be1919b
pass the experimental flag to the remote functions
cf7169a
updated the edit agent to listen to dom characterdatamodified events …
8ad1b9d
several bug fixes in live development
04ae860
report the event, not its children
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,6 +39,8 @@ define(function EditAgent(require, exports, module) { | |
|
|
||
| var EditorManager = require("editor/EditorManager"); | ||
|
|
||
| var _editedNode; | ||
|
|
||
| /** Find changed characters | ||
| * @param {string} old value | ||
| * @param {string} changed value | ||
|
|
@@ -74,28 +76,51 @@ define(function EditAgent(require, exports, module) { | |
| return { from: index, to: index + length, text: value }; | ||
| } | ||
|
|
||
| // Remote Event: Go to the given source node | ||
| function _onRemoteEdit(event, res) { | ||
| // res = {nodeId, name, value} | ||
| var node = DOMAgent.nodeWithId(res.nodeId); | ||
| node = node.children[0]; | ||
| if (!node.location) { | ||
| // WebInspector Event: DOM.characterDataModified | ||
| function _onCharacterDataModified(event, res) { | ||
| // res = {nodeId, characterData} | ||
| if (_editedNode.nodeId !== res.nodeId) { | ||
| return; | ||
| } | ||
|
|
||
| GotoAgent.open(DOMAgent.url); | ||
| var editor = EditorManager.getCurrentFullEditor(); | ||
| var codeMirror = editor._codeMirror; | ||
| var change = _findChangedCharacters(node.value, res.value); | ||
| var change = _findChangedCharacters(_editedNode.value, res.characterData); | ||
| if (change) { | ||
| var from = codeMirror.posFromIndex(node.location + change.from); | ||
| var to = codeMirror.posFromIndex(node.location + change.to); | ||
| var from = codeMirror.posFromIndex(_editedNode.location + change.from); | ||
| var to = codeMirror.posFromIndex(_editedNode.location + change.to); | ||
| exports.isEditing = true; | ||
| editor.document.replaceRange(change.text, from, to); | ||
| exports.isEditing = false; | ||
|
|
||
| var newPos = codeMirror.posFromIndex(node.location + change.from + change.text.length); | ||
| var newPos = codeMirror.posFromIndex(_editedNode.location + change.from + change.text.length); | ||
| editor.setCursorPos(newPos.line, newPos.ch); | ||
| } | ||
| } | ||
|
|
||
| // Remote Event: Go to the given source node | ||
| function _onRemoteEdit(event, res) { | ||
| // res = {nodeId, name, value} | ||
|
|
||
| // detach from DOM change events | ||
| if (res.value === "0") { | ||
| $(Inspector.DOM).off(".EditAgent"); | ||
| return; | ||
| } | ||
|
|
||
| // find and store the edited node | ||
| var node = DOMAgent.nodeWithId(res.nodeId); | ||
| node = node.children[0]; | ||
| if (!node.location) { | ||
| return; | ||
| } | ||
| _editedNode = node; | ||
|
|
||
| // attach to character data modified events | ||
| $(Inspector.DOM).on("characterDataModified.EditAgent", _onCharacterDataModified); | ||
| } | ||
|
|
||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The EditAgent now relies on a data-ld-edit event to enable/disable the editor + on DOM. characterDataModified to realize the actual changes. |
||
| /** Initialize the agent */ | ||
| function load() { | ||
| $(RemoteAgent).on("edit.EditAgent", _onRemoteEdit); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,7 @@ define(function HighlightAgent(require, exports, module) { | |
| if (res.value === "1") { | ||
| node = DOMAgent.nodeWithId(res.nodeId); | ||
| } | ||
| $(exports).triggerHandler("highlight", node); | ||
| $(exports).triggerHandler("highlight", [node]); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug fix: jQuery event parameters must be given as an array or bad things happen! |
||
| } | ||
|
|
||
| /** Hide in-browser highlighting */ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ define(function RemoteAgent(require, exports, module) { | |
|
|
||
| var $exports = $(exports); | ||
|
|
||
| var LiveDevelopment = require("LiveDevelopment/LiveDevelopment"); | ||
| var Inspector = require("LiveDevelopment/Inspector/Inspector"); | ||
|
|
||
| var _load; // deferred load | ||
|
|
@@ -48,7 +49,7 @@ define(function RemoteAgent(require, exports, module) { | |
| var request = new XMLHttpRequest(); | ||
| request.open("GET", "LiveDevelopment/Agents/RemoteFunctions.js"); | ||
| request.onload = function onLoad() { | ||
| var run = "window._LD=" + request.response + "()"; | ||
| var run = "window._LD=" + request.response + "(" + LiveDevelopment.config.experimental + ")"; | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By passing the experimental to RemoteFunctions.js, we can avoid commenting out experimental stuff there. |
||
| Inspector.Runtime.evaluate(run, function onEvaluate(res) { | ||
| console.assert(!res.wasThrown, res.result.description); | ||
| _objectId = res.result.objectId; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid changes that occur from the editor on the remote site to propagate back there, the DOMAgent must not push any changed node values if they have come from there (through the EditAgent).