From 27a95f634d351ad11c45ca835c9062b3851ce254 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 30 Jan 2011 00:31:38 +0400 Subject: [PATCH 1/3] add support for contextmenu --- lib/ace/css/editor.css | 2 +- lib/ace/editor.js | 14 ++++++++++---- lib/ace/keyboard/textinput.js | 20 +++++++++++++++++++- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/lib/ace/css/editor.css b/lib/ace/css/editor.css index df204e58..af359ae9 100644 --- a/lib/ace/css/editor.css +++ b/lib/ace/css/editor.css @@ -74,7 +74,7 @@ } .ace_editor textarea { - position: "absolute"; + position: absolute; z-index: -1; opacity: 0; width: 10px; diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 5e8f2a01..7394abd1 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -281,11 +281,11 @@ var Editor =function(renderer, session) { this.onCursorChange = function(e) { this.$highlightBrackets(); - + // move text input over the cursor // this is required for iOS and IME this.renderer.moveTextAreaToCursor(this.textInput.getElement()); - + this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite); if (!this.$blockScrolling && (!e || !e.blockScrolling)) { @@ -357,10 +357,16 @@ var Editor =function(renderer, session) { var pos = this.renderer.screenToTextCoordinates(pageX, pageY); pos.row = Math.max(0, Math.min(pos.row, this.session.getLength()-1)); - if (event.getButton(e) != 0) { - if (this.selection.isEmpty()) { + var button = event.getButton(e) + if (button != 0) { + var isEmpty = this.selection.isEmpty() + if (isEmpty) { this.moveCursorToPosition(pos); } + if(button == 2) { + this.textInput.onContextMenu({x: pageX, y: pageY}, isEmpty); + event.capture(this.container, function(){}, this.textInput.onContextMenuClose); + } return; } diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index f4ecac17..9bcecb2a 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -184,10 +184,28 @@ var TextInput = function(parentNode, host) { this.blur = function() { text.blur(); }; - + this.getElement = function() { return text; }; + + this.onContextMenu = function(mousePos, isEmpty){ + if(mousePos){ + text.style.cssText = 'position:fixed; z-index:1000;' + + 'left:' + (mousePos.x - 2) + 'px; top:' + (mousePos.y - 2) + 'px;' + + } + if(isEmpty) + text.value=''; + } + + this.onContextMenuClose = function(){ + setTimeout(function () { + sendText(); + }, 0); + text.style.position = ''; + text.style.zIndex = ''; + } }; exports.TextInput = TextInput; From cad1421cd922a448797176ab1e7536ef8ee1f93a Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 30 Jan 2011 00:41:45 +0400 Subject: [PATCH 2/3] moveTextAreaToCursor after updating cursor, to get right position --- lib/ace/editor.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/ace/editor.js b/lib/ace/editor.js index 7394abd1..149cea24 100644 --- a/lib/ace/editor.js +++ b/lib/ace/editor.js @@ -280,17 +280,17 @@ var Editor =function(renderer, session) { }; this.onCursorChange = function(e) { - this.$highlightBrackets(); - - // move text input over the cursor - // this is required for iOS and IME - this.renderer.moveTextAreaToCursor(this.textInput.getElement()); - this.renderer.updateCursor(this.getCursorPosition(), this.$overwrite); if (!this.$blockScrolling && (!e || !e.blockScrolling)) { this.renderer.scrollCursorIntoView(); } + + // move text input over the cursor + // this is required for iOS and IME + this.renderer.moveTextAreaToCursor(this.textInput.getElement()); + + this.$highlightBrackets(); this.$updateHighlightActiveLine(); }; From decc10e92293492c7d1c07ff94fedae92aadbad6 Mon Sep 17 00:00:00 2001 From: nightwing Date: Sun, 30 Jan 2011 01:26:13 +0400 Subject: [PATCH 3/3] fix for chrome --- lib/ace/keyboard/textinput.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/ace/keyboard/textinput.js b/lib/ace/keyboard/textinput.js index 9bcecb2a..097149a7 100644 --- a/lib/ace/keyboard/textinput.js +++ b/lib/ace/keyboard/textinput.js @@ -50,6 +50,7 @@ var TextInput = function(parentNode, host) { var inCompostion = false; var copied = false; + var tempStyle = ''; function sendText(valueToSend) { if (!copied) { @@ -190,21 +191,25 @@ var TextInput = function(parentNode, host) { }; this.onContextMenu = function(mousePos, isEmpty){ - if(mousePos){ + if (mousePos) { + if(!tempStyle) + tempStyle = text.style.cssText; text.style.cssText = 'position:fixed; z-index:1000;' + 'left:' + (mousePos.x - 2) + 'px; top:' + (mousePos.y - 2) + 'px;' } - if(isEmpty) + if (isEmpty) text.value=''; } this.onContextMenuClose = function(){ setTimeout(function () { + if (tempStyle) { + text.style.cssText = tempStyle; + tempStyle = ''; + } sendText(); }, 0); - text.style.position = ''; - text.style.zIndex = ''; } };