From bc7510acfb1d9ecafb6db754e58cb93e4ea3b556 Mon Sep 17 00:00:00 2001 From: Alexis Deveria Date: Mon, 12 Apr 2010 20:28:39 +0000 Subject: [PATCH] More minor improvents to text edit mode git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1518 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svgcanvas.js | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/editor/svgcanvas.js b/editor/svgcanvas.js index 352f46fc..98bf86d9 100644 --- a/editor/svgcanvas.js +++ b/editor/svgcanvas.js @@ -1603,7 +1603,6 @@ function BatchCommand(text) { if(elem.id == 'svgcontent') { // Process root element separately var res = canvas.getResolution(); - console.log('res',res); out.push(' width="' + res.w + '" height="' + res.h + '" xmlns="'+svgns+'"'); var nsuris = {}; @@ -3966,6 +3965,9 @@ function BatchCommand(text) { var pt = svgroot.createSVGPoint(); pt.x = mouse_x; pt.y = mouse_y; + + // No content, so return 0 + if(chardata.length == 1) return 0; // Determine if cursor should be on left or right of character var charpos = curtext.getCharNumAtPosition(pt); @@ -3998,7 +4000,7 @@ function BatchCommand(text) { var end = Math.max(i1, i2); setSelection(start, end, apply); } - + function screenToPt(x_in, y_in) { var out = { x: x_in, @@ -4050,7 +4052,7 @@ function BatchCommand(text) { var pt = screenToPt(mouse_x, mouse_y); setEndSelectionFromPoint(pt.x, pt.y, true); if(last_x === mouse_x && last_y === mouse_y && evt.target !== curtext) { - textActions.toSelectMode(); + textActions.toSelectMode(true); } }, setCursor: setCursor, @@ -4069,24 +4071,36 @@ function BatchCommand(text) { setCursorFromPoint(pt.x, pt.y); } }, - toSelectMode: function() { + toSelectMode: function(selectElem) { current_mode = "select"; clearInterval(blinker); blinker = null; if(selblock) $(selblock).attr('display','none'); if(cursor) $(cursor).attr('visibility','hidden'); - - canvas.clearSelection(); $(curtext).css('cursor', 'move'); - call("selected", [curtext]); - canvas.addToSelection([curtext], true); + if(selectElem) { + canvas.clearSelection(); + $(curtext).css('cursor', 'move'); + + call("selected", [curtext]); + canvas.addToSelection([curtext], true); + } + if(!curtext.textContent.length) { + // No content, so delete + canvas.deleteSelectedElements(); + } curtext = false; }, setInputElem: function(elem) { textinput = elem; }, + clear: function() { + if(current_mode == "textedit") { + textActions.toSelectMode(); + } + }, init: function(inputElem) { if(!curtext) return; @@ -4114,7 +4128,7 @@ function BatchCommand(text) { }); if(!len) { - var end = {x: textbb.x + (textbb.width/2)}; + var end = {x: textbb.x + (textbb.width/2), width: 0}; } for(var i=0; i