Skip to content
This repository has been archived by the owner on Apr 16, 2018. It is now read-only.

Commit

Permalink
added support for the selectAll Command (Fixed issue ckeditor#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
w8tcha committed Apr 7, 2013
1 parent 30e21a7 commit d321d66
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions codemirror/plugin.js
Expand Up @@ -63,7 +63,7 @@

var sourcearea = CKEDITOR.plugins.sourcearea;
editor.addMode('source', function(callback) {
if (typeof(CodeMirror) == 'undefined') {
if (typeof (CodeMirror) === 'undefined') {
CKEDITOR.scriptLoader.load([rootPath + 'js/codemirror.min.js'].concat(getCodeMirrorScripts()), function() {
loadCodeMirror(editor);
callback();
Expand Down Expand Up @@ -129,11 +129,10 @@
theme: config.theme,
onKeyEvent: function(codeMirror_Editor, evt) {
if (config.enableCodeFormatting) {
if (evt.type == "keydown" && evt.ctrlKey && evt.keyCode == 75 && !evt.shiftKey && !evt.altKey) {
var range = getSelectedRange();
var range = getSelectedRange();
if (evt.type === "keydown" && evt.ctrlKey && evt.keyCode === 75 && !evt.shiftKey && !evt.altKey) {
window["codemirror_" + editor.id].commentRange(true, range.from, range.to);
} else if (evt.type === "keydown" && evt.ctrlKey && evt.keyCode === 75 && evt.shiftKey && !evt.altKey) {
var range = getSelectedRange();
window["codemirror_" + editor.id].commentRange(false, range.from, range.to);
if (config.autoFormatOnUncomment) {
window["codemirror_" + editor.id].autoFormatRange(range.from, range.to);
Expand Down Expand Up @@ -233,16 +232,35 @@
}
}
editor.on('mode', function() {
editor.getCommand('source').setState(editor.mode == 'source' ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF);
editor.getCommand('source').setState(editor.mode === 'source' ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF);


});
editor.on('resize', function() {
if (window["editable_" + editor.id] && editor.mode == 'source') {
if (window["editable_" + editor.id] && editor.mode === 'source') {
var holderElement = window["editable_" + editor.id].getParent();
var holderHeight = holderElement.$.clientHeight + 'px';
var holderWidth = holderElement.$.clientWidth + 'px';
window["codemirror_" + editor.id].setSize(holderWidth, holderHeight);
}
});


var selectAllCommand = editor.commands.selectAll;

if (selectAllCommand !== null) {
selectAllCommand.on('exec', function () {
if (editor.mode === 'source') {
window["codemirror_" + editor.id].setSelection({
line: 0,
ch: 0
}, {
line: window["codemirror_" + editor.id].lineCount(),
ch: 0
});
}
});
}
}
});
var sourceEditable = CKEDITOR.tools.createClass({
Expand Down Expand Up @@ -292,9 +310,9 @@ CKEDITOR.plugins.sourcearea = {
editorFocus: false,
readOnly: 1,
exec: function(editor) {
if (editor.mode == 'wysiwyg') editor.fire('saveSnapshot');
if (editor.mode === 'wysiwyg') editor.fire('saveSnapshot');
editor.getCommand('source').setState(CKEDITOR.TRISTATE_DISABLED);
editor.setMode(editor.mode == 'source' ? 'wysiwyg' : 'source');
editor.setMode(editor.mode === 'source' ? 'wysiwyg' : 'source');
},
canUndo: false
},
Expand Down

0 comments on commit d321d66

Please sign in to comment.