More minor improvents to text edit mode

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1518 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
Alexis Deveria
2010-04-12 20:28:39 +00:00
parent 7ac3d0456b
commit bc7510acfb

View File

@@ -1603,7 +1603,6 @@ function BatchCommand(text) {
if(elem.id == 'svgcontent') { if(elem.id == 'svgcontent') {
// Process root element separately // Process root element separately
var res = canvas.getResolution(); var res = canvas.getResolution();
console.log('res',res);
out.push(' width="' + res.w + '" height="' + res.h + '" xmlns="'+svgns+'"'); out.push(' width="' + res.w + '" height="' + res.h + '" xmlns="'+svgns+'"');
var nsuris = {}; var nsuris = {};
@@ -3966,6 +3965,9 @@ function BatchCommand(text) {
var pt = svgroot.createSVGPoint(); var pt = svgroot.createSVGPoint();
pt.x = mouse_x; pt.x = mouse_x;
pt.y = mouse_y; 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 // Determine if cursor should be on left or right of character
var charpos = curtext.getCharNumAtPosition(pt); var charpos = curtext.getCharNumAtPosition(pt);
@@ -3998,7 +4000,7 @@ function BatchCommand(text) {
var end = Math.max(i1, i2); var end = Math.max(i1, i2);
setSelection(start, end, apply); setSelection(start, end, apply);
} }
function screenToPt(x_in, y_in) { function screenToPt(x_in, y_in) {
var out = { var out = {
x: x_in, x: x_in,
@@ -4050,7 +4052,7 @@ function BatchCommand(text) {
var pt = screenToPt(mouse_x, mouse_y); var pt = screenToPt(mouse_x, mouse_y);
setEndSelectionFromPoint(pt.x, pt.y, true); setEndSelectionFromPoint(pt.x, pt.y, true);
if(last_x === mouse_x && last_y === mouse_y && evt.target !== curtext) { if(last_x === mouse_x && last_y === mouse_y && evt.target !== curtext) {
textActions.toSelectMode(); textActions.toSelectMode(true);
} }
}, },
setCursor: setCursor, setCursor: setCursor,
@@ -4069,24 +4071,36 @@ function BatchCommand(text) {
setCursorFromPoint(pt.x, pt.y); setCursorFromPoint(pt.x, pt.y);
} }
}, },
toSelectMode: function() { toSelectMode: function(selectElem) {
current_mode = "select"; current_mode = "select";
clearInterval(blinker); clearInterval(blinker);
blinker = null; blinker = null;
if(selblock) $(selblock).attr('display','none'); if(selblock) $(selblock).attr('display','none');
if(cursor) $(cursor).attr('visibility','hidden'); if(cursor) $(cursor).attr('visibility','hidden');
canvas.clearSelection();
$(curtext).css('cursor', 'move'); $(curtext).css('cursor', 'move');
call("selected", [curtext]); if(selectElem) {
canvas.addToSelection([curtext], true); 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; curtext = false;
}, },
setInputElem: function(elem) { setInputElem: function(elem) {
textinput = elem; textinput = elem;
}, },
clear: function() {
if(current_mode == "textedit") {
textActions.toSelectMode();
}
},
init: function(inputElem) { init: function(inputElem) {
if(!curtext) return; if(!curtext) return;
@@ -4114,7 +4128,7 @@ function BatchCommand(text) {
}); });
if(!len) { 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<len; i++) { for(var i=0; i<len; i++) {
@@ -4136,7 +4150,8 @@ function BatchCommand(text) {
// Add a last bbox for cursor at end of text // Add a last bbox for cursor at end of text
chardata.push({ chardata.push({
x: end.x x: end.x,
width: 0
}); });
} }
@@ -7159,6 +7174,7 @@ function BatchCommand(text) {
this.setMode = function(name) { this.setMode = function(name) {
pathActions.clear(true); pathActions.clear(true);
textActions.clear();
cur_properties = (selectedElements[0] && selectedElements[0].nodeName == 'text') ? cur_text : cur_shape; cur_properties = (selectedElements[0] && selectedElements[0].nodeName == 'text') ? cur_text : cur_shape;
current_mode = name; current_mode = name;