-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Js2coffee Integration (issues/126) #193
base: master
Are you sure you want to change the base?
Changes from all commits
0df54cc
4ab660c
ce060c8
4391a0c
1ec460a
2fd0c2a
3536ea1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2208,44 +2208,15 @@ function changeEditorText(paneState, text) { | |
if (text.length && text.charAt(text.length - 1) != '\n') { | ||
text += '\n'; | ||
} | ||
paneState.changeHandler.suppressChange = true; | ||
var saved = {}, editor = paneState.editor, session = editor.session; | ||
saved.selection = session.selection.toJSON() | ||
saved.atend = session.selection.getCursor().row >= session.getLength() - 1; | ||
saved.folds = session.getAllFolds().map(function(fold) { | ||
return { | ||
start : fold.start, | ||
end : fold.end, | ||
placeholder : fold.placeholder | ||
}; | ||
}); | ||
saved.scrollTop = session.getScrollTop() | ||
saved.scrollLeft = session.getScrollLeft() | ||
var editor = paneState.editor, session = editor.session; | ||
|
||
session.changeHandler.suppressChange = true; | ||
|
||
// Now set the text and restore everything. | ||
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. why was all this logic deleted as part of this change? 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. this method had not used anyway according to my knowledge. And also it seems like a copy of another method. So, I saw them as useless things. Anyway, I'l check it again and let you know 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. @davidbau Do you have any idea about what these line are. And the need of them here. Appreciate if some one can help me. 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. Yup, so the call to set text is used via external API. The idea is that a tutorial website could set the text on a pencilcode program as part of a tutorial. All the care with selections etc means that, if a student already has some code, setting the text will modify the code but keep the selection in the same place. 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. @davidbau is it still required to keep records of selections and scrolled points even after changing the language. And would that be practical. 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. No, when changing languages we shouldn't keep selections and things like that. There should probably be an additional argument to this function to control whether it can discard selection. Switching language would set it to "true". 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. Sure @davidbau . But, I couldn't find any where else using this method. That's why I changed this. Anyway, it's better to keep a switch. |
||
session.setValue(text); | ||
|
||
session.selection.fromJSON(saved.selection); | ||
try { | ||
saved.folds.forEach(function(fold){ | ||
session.addFold(fold.placeholder, | ||
ace.require('ace/range').Range.fromPoints(fold.start, fold.end)); | ||
}); | ||
} catch(e) { } | ||
|
||
session.setScrollTop(saved.scrollTop); | ||
session.setScrollLeft(saved.scrollLeft); | ||
|
||
// If the cursor used to be at the end, keep it at the end. | ||
if (session.selection.isEmpty() && saved.atend) { | ||
session.selection.moveCursorTo(session.getLength() - 1, 0); | ||
} | ||
|
||
// TODO: detect the case where some text is added and we should | ||
// scroll down to make the changes visible. | ||
|
||
paneState.changeHandler.suppressChange = false; | ||
paneState.changeHandler(); | ||
session.changeHandler.suppressChange = false; | ||
session.changeHandler(); | ||
} | ||
|
||
function editorMimeType(paneState) { | ||
|
@@ -2650,6 +2621,7 @@ function setupAceEditor(pane, elt, editor, mode, text) { | |
// Publish the update event for hosting frame. | ||
if (hasSubscribers()) publish('update', [session.getValue()]); | ||
}); | ||
editor.getSession().changeHandler = changeHandler; | ||
$(elt).data('changeHandler', changeHandler); | ||
editor.getSession().on('change', changeHandler); | ||
// Fold any blocks with a line that ends with "# fold" or "// fold" | ||
|
@@ -2736,6 +2708,10 @@ function setPaneEditorLanguageType(pane, type) { | |
paneState.dropletEditor.setMode( | ||
dropletModeForMimeType(type), | ||
dropletOptionsForMimeType(type)); | ||
|
||
//Modify the code to the changed language | ||
fireEvent('editorLanguageChanged',[pane,type]); | ||
|
||
paneState.editor.getSession().setMode(modeForMimeType(type)); | ||
paneState.meta = filetype.effectiveMeta(paneState.meta); | ||
paneState.meta.type = type; | ||
|
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.
Should we use a tagged version instad of #master?
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.
js2coffee is not available as a bower package. So, I had to add the tagged version