Commit 552ab10f authored by campaign's avatar campaign

添加editor

parent 707f25e0
......@@ -40,6 +40,6 @@ var MinderEvent = kity.createClass( 'MindEvent', {
return this._canstop && this._immediatelyStoped;
},
preventDefault:function(){
e.originEvent.preventDefault();
this.originEvent.preventDefault();
}
} );
\ No newline at end of file
......@@ -13,7 +13,6 @@ kity.extendClass( Minder, {
},
// TODO: mousemove lazy bind
_bindPaperEvents: function () {
var minder = this;
this._paper.on( 'click mousedown mouseup mousemove touchstart touchmove touchend', this._firePharse.bind( this ) );
},
_bindKeyboardEvents: function () {
......@@ -30,8 +29,11 @@ kity.extendClass( Minder, {
}
preEvent = new MinderEvent( 'pre' + e.type, e, false );
executeEvent = new MinderEvent( e.type, e, false );
this._fire( preEvent );
this._fire( executeEvent );
this._fire(new MinderEvent('after' + e.type,e,false));
if ( ~'mousedown mouseup keydown keyup'.indexOf( e.type ) ) {
this._interactChange( e );
}
......
......@@ -65,7 +65,7 @@ kity.extendClass( Minder, function () {
this._selectedNodes = nodes;
},
isSingleSelect:function(){
return this.getSelectedNodes().length == 1
return this._selectedNodes.length == 1
}
}
}() );
\ No newline at end of file
......@@ -11,6 +11,12 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
this.rc = new kity.Group();
this.rc.minderNode = this;
},
setText:function(text){
this.setData('text',text)
},
getText:function(){
return this.getData('text')
},
isRoot:function(){
return this.getParent() == null ? true : false;
},
......
......@@ -3,17 +3,22 @@ KityMinder.registerModule( "TextEditModule", function () {
var receiver = new Minder.Receiver();
var range = new Minder.Range();
this.getPaper().addShape(cursor);
return {
//插入光标
"init":function(){
this.getPaper().addShape(cursor);
},
"events": {
'mousedown':function(e){
var originEvent = e.originEvent;
var targetShape = e.kityEvent.targetShape;
'aftermousedown':function(e){
if(this.isSingleSelect()){
debugger
var node = this.getSelectedNode();
var node_rc = node.getRenderContainer();
var position = e.getPosition();
if(targetShape.getType() != 'Text'){
// var offset = e.getPosition();
// cursor.setShow().setPosition(offset);
if(node_rc.getType() != 'Text'){
var offset = e.getPosition();
cursor.setShow().setPosition(offset);
// receiver.clear()
// .setTextShape()
// .setTextShapeSize(cursor.height)
......@@ -21,22 +26,28 @@ KityMinder.registerModule( "TextEditModule", function () {
// .setPosition(position)
// .setRange(range,0)
// .setCursor(cursor)
}else{
receiver.setCursor(cursor)
.setKityMinder(this)
.setMinderNode(e.getTargetNode())
.setTextShape(targetShape)
.setMinderNode(node)
.setTextShape(node_rc)
.setCursorHeight()
.setCurrentIndex(position)
.updateCursor()
.setRange(range);
.setRange(range,0);
}else{
// receiver.setCursor(cursor)
// .setKityMinder(this)
// .setMinderNode(e.getTargetNode())
// .setTextShape(node_rc)
// .setCursorHeight()
// .setCurrentIndex(position)
// .updateCursor()
// .setRange(range);
}
},
'kbcreateandedit':function(){
receiver.clear()
}
}
}
......
......@@ -67,8 +67,9 @@ Minder.Receiver = kity.createClass('Receiver',{
case 'keyup':
var text = (this.container.textContent || this.container.innerText).replace(/\u200b/g,'');
this.textShape.setContent(text);
this.minderNode.setData('text',text);
this.km.execCommand('renderNode',this.minderNode);
this.minderNode.setText(text);
this.km.renderNode(this.minderNode);
this.updateTextData();
this.updateCursor();
this.timer = setTimeout(function(){
......
......@@ -66,11 +66,12 @@ KityMinder.registerModule( "KeyboardModule", function () {
case 13:
// Enter
this.execCommand('appendSiblingNode',new MinderNode('Topic'));
e.preventDefault();
break;
case 9:
// Tab
this.execCommand('appendChildNode',new MinderNode('Topic'));
e.preventDefault();
break;
case 8:
case 46:
......@@ -88,11 +89,12 @@ KityMinder.registerModule( "KeyboardModule", function () {
40: 'down'
}[ e.originEvent.keyCode ]);
}
e.preventDefault();
break;
}
e.preventDefault();
}
}
}
......
KityMinder.registerModule( "MouseModule", function () {
var SingleSelectCommand = kity.createClass( 'SingleSelectCommand', {
base: Command,
execute: function ( km, node ) {
var deltaNodes = km.getSelectedNodes();
km.clearSelect();
if ( node ) {
km.selectSingle( node );
deltaNodes.push( node );
}
km.execCommand( 'rendernode', deltaNodes );
this.setContentChanged( false );
}
} );
var Draggable = ( function () {
var Paper = kity.Paper;
......@@ -156,17 +143,18 @@ KityMinder.registerModule( "MouseModule", function () {
}
return {
"init": function () {
kity.extendClass( kity.Paper, Draggable );
this._paper.drag();
},
"commands": {
'selectsingle': SingleSelectCommand
// kity.extendClass( kity.Paper, Draggable );
// this._paper.drag();
},
"events": {
'mousedown touchstart': function ( e ) {
if ( e.originEvent.touches && e.originEvent.touches.length != 1 ) return;
var clickNode = e.getTargetNode();
this.execCommand( 'selectsingle', clickNode );
if(clickNode){
this.select(clickNode)
}else{
this.removeAllSelectedNodes()
}
},
'touchstart': function ( e ) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment