From 432873ed4669609389630b65631725db5dff0212 Mon Sep 17 00:00:00 2001 From: Fabian Jakobs Date: Sun, 13 Feb 2011 15:54:21 +0100 Subject: [PATCH] implement split line command --- lib/ace/commands/default_commands.js | 4 ++++ lib/ace/editor.js | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/ace/commands/default_commands.js b/lib/ace/commands/default_commands.js index aa243c5e..35174be8 100644 --- a/lib/ace/commands/default_commands.js +++ b/lib/ace/commands/default_commands.js @@ -257,6 +257,10 @@ canon.addCommand({ } }); canon.addCommand({ +canon.addCommand({ + name: "splitline", + exec: function(env, args, request) { env.editor.splitLine(); } +}); name: "transposeletters", exec: function(env, args, request) { env.editor.transposeLetters(); } }); diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 996efabe..2a9989dc 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -565,6 +565,19 @@ var Editor =function(renderer, session) { this.clearSelection(); }; + this.splitLine = function() { + if (this.$readOnly) + return; + + if (!this.selection.isEmpty()) { + this.session.remove(this.getSelectionRange()); + this.clearSelection(); + } + + var cursor = this.getCursorPosition(); + this.insert("\n"); + this.moveCursorToPosition(cursor); + }; this.transposeLetters = function() { if (this.$readOnly)