-
Notifications
You must be signed in to change notification settings - Fork 884
Conversation
Thanks! Would it be possible to add an examples/monaco.html file that demos this working? That'll also be helpful for anybody that tries to use this down the road. |
Done. I followed this to integrate the editor. |
The other alternative could be to have |
Hey! What would be the better way to have the editor in examples? |
Could you use this CDN version? https://cdnjs.com/libraries/monaco-editor Else, having people install node modules first is probably fine. |
Hey! I updated that. Have a look. |
Updated the detach function following this: https://stackoverflow.com/questions/50405510/remove-listner-from-monaco-editor/50413982#50413982 |
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.
Woo! I was able to test this out and it seems to work quite well. Nice work!
I've left a few comments (though I didn't review the actual adapter too deeply). Please take a look and then we can likely get this merged. Thanks for putting this together!
package.json
Outdated
"jsdom": ">3", | ||
"firebase": "^3 || ^4" | ||
"monaco-editor": "^0.13.1" |
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.
can you make this a devDependency please? It's necessary to run the examples but we don't want to automatically depend on monaco-editor when you install firepad (since you may be using it with ace / codemirror)
test/index.html
Outdated
@@ -15,6 +15,9 @@ | |||
<!-- CodeMirror --> | |||
<script src="../bower_components/codemirror/lib/codemirror.js"></script> | |||
|
|||
<!-- Monaco --> | |||
<script src="../bower_components/monaco-editor-official/monaco.d.ts"></script> |
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.
Hrm... I don't see monaco-editor-official added to ~/bower.json and when I open this file, there's a 404. But the tests still pass because I don't think they depend on this. So maybe just remove this script include?
var firepadRef = getExampleRef(); | ||
|
||
//// Create Monaco and firepad. | ||
require.config({ paths: {'vs': './../node_modules/monaco-editor/min/vs'}}); |
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.
Hrm... You're pulling in loader.js from the CDN but then loading from node_modules here... Ideally we'd use one or the other (and the CDN would be best so people can just copy/paste the example and have it work).
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.
I'm not that sure about the CDN thing, so added loader import from local only.
examples/monaco.html
Outdated
|
||
<!-- Firepad --> | ||
<link rel="stylesheet" href="https://cdn.firebase.com/libs/firepad/1.4.0/firepad.css" /> | ||
<script src="https://cdn.firebase.com/libs/firepad/1.4.0/firepad.min.js"></script> |
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.
Obviously this doesn't work yet. I can change it to 1.5.0 once it's released... but given that as-written, this depends on local files (node_modules/monaco-editor) you could also just change this to ../dist/firepad.min.js so that the example works as-is.
lib/firepad.js
Outdated
if (!CodeMirror && !ace) { | ||
throw new Error('Couldn\'t find CodeMirror or ACE. Did you forget to include codemirror.js or ace.js?'); | ||
if (!CodeMirror && !ace && !global.monaco) { | ||
throw new Error('Couldn\'t find CodeMirror, ACE or Monaco. Did you forget to include codemirror.js/ace.js/monaco.d.ts?'); |
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.
Hrm. I thought a .d.ts file only has type definitions and so it won't help to include it, right (it's not going to create global variables and whatnot). Can you fix this to be more correct, or just remove it?
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.
I tried to remove this, but it is giving some error.
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 be clear, I just meant remove "/monaco.d.ts" from the error message...
lib/firepad.js
Outdated
this.monaco_ = this.editor_ = place; | ||
curValue = this.monaco_.getValue(); | ||
if (curValue !== '') { | ||
throw new Error("Can't initialize Firepad with an Monaco instance that already contains text."); |
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.
"an" => "a"
lib/monaco-adapter.js
Outdated
}; | ||
|
||
MonacoAdapter.prototype.detach = function() { | ||
this.monaco.onDidChangeModelContent(this.onChange).dispose(); |
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.
I haven't dug into Monaco's implementation, but I kinda' suspect that this is attaching a new listener and then immediately removing it, and likely isn't removing the listener you attached in the constructor.
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.
Yeah! Even I'm not that sure about this. A better addition would be to have
this.onChange.dispose()
this will call the dispose of for the actual attached onChange
.
Hey! I updated the changes. Have a look. :D |
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.
Sorry... One more question about the detach() code. :-)
lib/monaco-adapter.js
Outdated
this.onChange.dispose(); | ||
this.onBlur.dispose(); | ||
this.onFocus.dispose(); | ||
this.onCursorActivity.dispose(); |
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.
Hrm... Sorry to keep bugging you about this code, but have you tried calling firepad.dispose() to verify this actually runs okay? Unless calling this.monaco.onDidChangeModelContent(this.onChange)
actually mutates your onChange function and adds a dispose property, I'd guess that this will not work correctly.
I would guess that what you need to do is something like:
var changeHandler = this.monaco.onDidChangeModelContent(this.onChange);
var didBlurHandler = this.monaco.onDidBlurEditor(this.onBlur);
...
this.detach = function() {
changeHandler.dispose();
blurHandler.dispose();
...
}
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.
No worries, Thank you for helping me out with this. I'm clueless about the detach function.
Is this okay? Do let me know if I've to make any other change. Actually, I'm not aware of the functioning of |
Thanks! It wasn't quite right, but I went ahead and merged it and then submitted a fix. :-) |
I've pushed a new v1.5.0 npm module of firepad with the monaco support. Thanks for tackling this! |
Thank you so much for helping me out with this. :) |
* New MonacoAdapter class added and plumbed into lib/firepad.js, etc. * examples/monaco.html added to demonstrate it.
Add support for monaco-editor.
I'm not sure, how do I've to update tests.
Also, I'm not sure about the detach thing. I tried to look for it, but unable to find anything for that.
Could someone help me with these 2 things?