Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
02f04f4c
Commit
02f04f4c
authored
Jun 25, 2014
by
campaign
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
模拟光标这个整体调整
parent
82e40daf
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
223 additions
and
324 deletions
+223
-324
connect.js
src/core/connect.js
+1
-1
minder.js
src/core/minder.js
+0
-3
minder.node.js
src/core/minder.node.js
+9
-2
dragtree.js
src/module/dragtree.js
+3
-3
editor.js
src/module/editor.js
+136
-288
editor.receiver.js
src/module/editor.receiver.js
+53
-19
editor.selection.js
src/module/editor.selection.js
+6
-2
history.js
src/module/history.js
+4
-1
node.js
src/module/node.js
+1
-1
select.js
src/module/select.js
+5
-4
text.js
src/module/text.js
+5
-0
No files found.
src/core/connect.js
View file @
02f04f4c
...
@@ -69,7 +69,7 @@ kity.extendClass(Minder, {
...
@@ -69,7 +69,7 @@ kity.extendClass(Minder, {
KityMinder
.
registerModule
(
'Connect'
,
{
KityMinder
.
registerModule
(
'Connect'
,
{
events
:
{
events
:
{
'node
create
'
:
function
(
e
)
{
'node
attach
'
:
function
(
e
)
{
this
.
createConnect
(
e
.
node
);
this
.
createConnect
(
e
.
node
);
},
},
'noderemove'
:
function
(
e
)
{
'noderemove'
:
function
(
e
)
{
...
...
src/core/minder.js
View file @
02f04f4c
...
@@ -88,9 +88,6 @@ var Minder = KityMinder.Minder = kity.createClass('KityMinder', {
...
@@ -88,9 +88,6 @@ var Minder = KityMinder.Minder = kity.createClass('KityMinder', {
this
.
_shortcutkeys
=
{};
this
.
_shortcutkeys
=
{};
this
.
_bindshortcutKeys
();
this
.
_bindshortcutKeys
();
},
},
isTextEditStatus
:
function
()
{
return
false
;
},
addShortcutKeys
:
function
(
cmd
,
keys
)
{
addShortcutKeys
:
function
(
cmd
,
keys
)
{
var
obj
=
{},
var
obj
=
{},
km
=
this
;
km
=
this
;
...
...
src/core/minder.node.js
View file @
02f04f4c
...
@@ -11,13 +11,20 @@ kity.extendClass(Minder, {
...
@@ -11,13 +11,20 @@ kity.extendClass(Minder, {
createNode
:
function
(
unknown
,
parent
,
index
)
{
createNode
:
function
(
unknown
,
parent
,
index
)
{
var
node
=
new
MinderNode
(
unknown
);
var
node
=
new
MinderNode
(
unknown
);
this
.
fire
(
'nodecreate'
,
{
node
:
node
});
this
.
appendNode
(
node
,
parent
,
index
);
return
node
;
},
appendNode
:
function
(
node
,
parent
,
index
)
{
if
(
parent
)
parent
.
insertChild
(
node
,
index
);
if
(
parent
)
parent
.
insertChild
(
node
,
index
);
this
.
handelNodeCreate
(
node
);
this
.
handelNodeCreate
(
node
);
this
.
fire
(
'node
create
'
,
{
this
.
fire
(
'node
attach
'
,
{
node
:
node
node
:
node
});
});
return
node
;
return
this
;
},
},
removeNode
:
function
(
node
)
{
removeNode
:
function
(
node
)
{
...
...
src/module/dragtree.js
View file @
02f04f4c
...
@@ -327,16 +327,16 @@ KityMinder.registerModule('DragTree', function() {
...
@@ -327,16 +327,16 @@ KityMinder.registerModule('DragTree', function() {
dragger
=
new
TreeDragger
(
this
);
dragger
=
new
TreeDragger
(
this
);
},
},
events
:
{
events
:
{
'mousedown'
:
function
(
e
)
{
'
normal.mousedown inputready.
mousedown'
:
function
(
e
)
{
// 单选中根节点也不触发拖拽
// 单选中根节点也不触发拖拽
if
(
e
.
getTargetNode
()
&&
e
.
getTargetNode
()
!=
this
.
getRoot
())
{
if
(
e
.
getTargetNode
()
&&
e
.
getTargetNode
()
!=
this
.
getRoot
())
{
dragger
.
dragStart
(
e
.
getPosition
(
this
.
getRenderContainer
()));
dragger
.
dragStart
(
e
.
getPosition
(
this
.
getRenderContainer
()));
}
}
},
},
'mousemove'
:
function
(
e
)
{
'
normal.
mousemove'
:
function
(
e
)
{
dragger
.
dragMove
(
e
.
getPosition
(
this
.
getRenderContainer
()));
dragger
.
dragMove
(
e
.
getPosition
(
this
.
getRenderContainer
()));
},
},
'mouseup'
:
function
(
e
)
{
'
normal.
mouseup'
:
function
(
e
)
{
dragger
.
dragEnd
(
e
.
getPosition
(
this
.
getRenderContainer
()));
dragger
.
dragEnd
(
e
.
getPosition
(
this
.
getRenderContainer
()));
e
.
stopPropagation
();
e
.
stopPropagation
();
this
.
fire
(
'contentchange'
);
this
.
fire
(
'contentchange'
);
...
...
src/module/editor.js
View file @
02f04f4c
This diff is collapsed.
Click to expand it.
src/module/editor.receiver.js
View file @
02f04f4c
...
@@ -12,17 +12,10 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -12,17 +12,10 @@ Minder.Receiver = kity.createClass('Receiver', {
this
.
isTypeText
=
false
;
this
.
isTypeText
=
false
;
return
this
;
return
this
;
},
},
setTextEditStatus
:
function
(
status
)
{
constructor
:
function
(
km
,
sel
,
range
)
{
this
.
textEditStatus
=
status
||
false
;
return
this
;
},
isTextEditStatus
:
function
()
{
return
this
.
textEditStatus
;
},
constructor
:
function
(
km
)
{
var
me
=
this
;
var
me
=
this
;
this
.
setKityMinder
(
km
);
this
.
setKityMinder
(
km
);
this
.
textEditStatus
=
false
;
var
_div
=
document
.
createElement
(
'div'
);
var
_div
=
document
.
createElement
(
'div'
);
_div
.
setAttribute
(
'contenteditable'
,
true
);
_div
.
setAttribute
(
'contenteditable'
,
true
);
_div
.
className
=
'km_receiver'
;
_div
.
className
=
'km_receiver'
;
...
@@ -33,9 +26,11 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -33,9 +26,11 @@ Minder.Receiver = kity.createClass('Receiver', {
});
});
}
}
utils
.
addCssRule
(
'km_receiver_css'
,
' .km_receiver{white-space:nowrap;position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);'
);
//
utils
.
addCssRule
(
'km_receiver_css'
,
' .km_receiver{white-space:nowrap;position:absolute;padding:0;margin:0;word-wrap:break-word;clip:rect(1em 1em 1em 1em);'
);
//
this
.
km
.
on
(
'textedit.beforekeyup textedit.beforekeydown textedit.keypress textedit.paste'
,
utils
.
proxy
(
this
.
keyboardEvents
,
this
));
this
.
km
.
on
(
'
inputready.beforekeyup inputready.beforekeydown
textedit.beforekeyup textedit.beforekeydown textedit.keypress textedit.paste'
,
utils
.
proxy
(
this
.
keyboardEvents
,
this
));
this
.
timer
=
null
;
this
.
timer
=
null
;
this
.
index
=
0
;
this
.
index
=
0
;
this
.
selection
=
sel
;
this
.
range
=
range
;
},
},
setRange
:
function
(
range
,
index
)
{
setRange
:
function
(
range
,
index
)
{
...
@@ -76,15 +71,30 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -76,15 +71,30 @@ Minder.Receiver = kity.createClass('Receiver', {
},
},
setMinderNode
:
function
(
node
)
{
setMinderNode
:
function
(
node
)
{
this
.
minderNode
=
node
;
this
.
minderNode
=
node
;
//更新minderNode下的textshape
this
.
setTextShape
(
node
.
getTextShape
());
//更新textshape的baseOffset
this
.
setBaseOffset
();
//更新接受容器的样式
this
.
setContainerStyle
();
//更新textOffsetData数据
this
.
updateTextOffsetData
();
//更新选取高度
this
.
setSelectionHeight
();
//更新接收容器内容
this
.
setContainerTxt
();
return
this
;
return
this
;
},
},
getMinderNode
:
function
(){
return
this
.
minderNode
;
},
keyboardEvents
:
function
(
e
)
{
keyboardEvents
:
function
(
e
)
{
clearTimeout
(
this
.
timer
);
clearTimeout
(
this
.
timer
);
var
me
=
this
;
var
me
=
this
;
var
orgEvt
=
e
.
originEvent
;
var
orgEvt
=
e
.
originEvent
;
var
keyCode
=
orgEvt
.
keyCode
;
var
keyCode
=
orgEvt
.
keyCode
;
var
keys
=
KityMinder
.
keymap
;
function
setTextToContainer
()
{
function
setTextToContainer
()
{
if
(
!
me
.
range
.
hasNativeRange
())
{
if
(
!
me
.
range
.
hasNativeRange
())
{
...
@@ -109,7 +119,7 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -109,7 +119,7 @@ Minder.Receiver = kity.createClass('Receiver', {
me
.
minderNode
.
render
();
me
.
minderNode
.
render
();
clearTimeout
(
me
.
inputTextTimer
);
clearTimeout
(
me
.
inputTextTimer
);
me
.
inputTextTimer
=
setTimeout
(
function
(){
me
.
inputTextTimer
=
setTimeout
(
function
(){
me
.
km
.
layout
(
300
);
me
.
km
.
layout
();
},
250
);
},
250
);
me
.
textShape
=
me
.
minderNode
.
getRenderer
(
'TextRenderer'
).
getRenderShape
();
me
.
textShape
=
me
.
minderNode
.
getRenderer
(
'TextRenderer'
).
getRenderShape
();
...
@@ -117,15 +127,14 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -117,15 +127,14 @@ Minder.Receiver = kity.createClass('Receiver', {
me
.
textShape
.
setOpacity
(
0
);
me
.
textShape
.
setOpacity
(
0
);
}
}
me
.
setBaseOffset
();
me
.
setBaseOffset
();
me
.
updateTextData
();
me
.
updateTextOffsetData
();
me
.
updateIndex
();
me
.
updateIndex
();
me
.
updateSelection
();
me
.
updateSelection
();
me
.
timer
=
setTimeout
(
function
()
{
me
.
timer
=
setTimeout
(
function
()
{
me
.
selection
.
setShow
();
me
.
selection
.
setShow
();
},
300
);
},
300
);
me
.
km
.
setStatus
(
'textedit'
);
}
}
...
@@ -144,8 +153,14 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -144,8 +153,14 @@ Minder.Receiver = kity.createClass('Receiver', {
switch
(
keyCode
)
{
switch
(
keyCode
)
{
case
keymap
.
Enter
:
case
keymap
.
Enter
:
case
keymap
.
Tab
:
case
keymap
.
Tab
:
case
keymap
.
left
:
case
keymap
.
right
:
case
keymap
.
up
:
case
keymap
.
down
:
if
(
this
.
selection
.
isShow
()){
if
(
this
.
selection
.
isShow
()){
this
.
clear
().
setTextEditStatus
(
false
);
this
.
clear
();
this
.
km
.
setStatus
(
'inputready'
);
clearTimeout
(
me
.
inputTextTimer
);
e
.
preventDefault
();
e
.
preventDefault
();
}
else
{
}
else
{
this
.
km
.
setStatus
(
'normal'
);
this
.
km
.
setStatus
(
'normal'
);
...
@@ -157,6 +172,12 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -157,6 +172,12 @@ Minder.Receiver = kity.createClass('Receiver', {
case
keymap
.
Alt
:
case
keymap
.
Alt
:
case
keymap
.
Cmd
:
case
keymap
.
Cmd
:
return
;
return
;
case
keymap
.
Del
:
case
keymap
.
Backspace
:
if
(
!
this
.
selection
.
isShow
()){
this
.
km
.
setStatus
(
'normal'
);
return
;
}
}
}
if
(
e
.
originEvent
.
ctrlKey
||
e
.
originEvent
.
metaKey
)
{
if
(
e
.
originEvent
.
ctrlKey
||
e
.
originEvent
.
metaKey
)
{
...
@@ -197,7 +218,6 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -197,7 +218,6 @@ Minder.Receiver = kity.createClass('Receiver', {
}
}
if
(
this
.
keydownNode
===
this
.
minderNode
)
{
if
(
this
.
keydownNode
===
this
.
minderNode
)
{
this
.
rollbackStatus
();
this
.
rollbackStatus
();
this
.
setTextEditStatus
(
false
);
this
.
clear
();
this
.
clear
();
}
}
e
.
preventDefault
();
e
.
preventDefault
();
...
@@ -205,6 +225,7 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -205,6 +225,7 @@ Minder.Receiver = kity.createClass('Receiver', {
case
keymap
.
Del
:
case
keymap
.
Del
:
case
keymap
.
Backspace
:
case
keymap
.
Backspace
:
case
keymap
.
Spacebar
:
case
keymap
.
Spacebar
:
setTextToContainer
();
setTextToContainer
();
return
;
return
;
}
}
...
@@ -222,7 +243,7 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -222,7 +243,7 @@ Minder.Receiver = kity.createClass('Receiver', {
this
.
index
=
this
.
range
.
getStart
().
startOffset
;
this
.
index
=
this
.
range
.
getStart
().
startOffset
;
return
this
;
return
this
;
},
},
updateTextData
:
function
()
{
updateText
Offset
Data
:
function
()
{
this
.
textShape
.
textData
=
this
.
getTextOffsetData
();
this
.
textShape
.
textData
=
this
.
getTextOffsetData
();
return
this
;
return
this
;
},
},
...
@@ -406,18 +427,31 @@ Minder.Receiver = kity.createClass('Receiver', {
...
@@ -406,18 +427,31 @@ Minder.Receiver = kity.createClass('Receiver', {
return
this
;
return
this
;
},
},
updateRange
:
function
(
range
)
{
updateRange
:
function
(
range
)
{
range
=
range
||
this
.
range
;
var
node
=
this
.
container
.
firstChild
;
var
node
=
this
.
container
.
firstChild
;
range
.
setStart
(
node
,
this
.
selection
.
startOffset
);
range
.
setStart
(
node
,
this
.
selection
.
startOffset
);
range
.
setEnd
(
node
,
this
.
selection
.
endOffset
);
range
.
setEnd
(
node
,
this
.
selection
.
endOffset
);
range
.
select
();
range
.
select
();
return
this
;
return
this
;
},
},
updateContainerRangeBySel
:
function
(){
this
.
updateRange
(
this
.
range
)
},
setIndex
:
function
(
index
)
{
setIndex
:
function
(
index
)
{
this
.
index
=
index
;
this
.
index
=
index
;
return
this
;
return
this
;
},
},
setContainerTxt
:
function
(
txt
)
{
setContainerTxt
:
function
(
txt
)
{
this
.
container
.
textContent
=
txt
;
this
.
container
.
textContent
=
txt
||
this
.
textShape
.
getContent
()
;
return
this
;
return
this
;
},
setReady
:
function
(){
this
.
_ready
=
true
;
},
clearReady
:
function
(){
this
.
_ready
=
false
;
},
isReady
:
function
(){
return
this
.
_ready
;
}
}
});
});
\ No newline at end of file
src/module/editor.selection.js
View file @
02f04f4c
...
@@ -82,10 +82,12 @@ Minder.Selection = kity.createClass( 'Selection', {
...
@@ -82,10 +82,12 @@ Minder.Selection = kity.createClass( 'Selection', {
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
);
console
.
log
(
e
);
}
}
return
this
.
update
();
this
.
update
();
return
this
;
},
},
setHeight
:
function
(
height
)
{
setHeight
:
function
(
height
)
{
this
.
height
=
height
;
this
.
height
=
height
;
return
this
;
},
},
setHide
:
function
()
{
setHide
:
function
()
{
clearInterval
(
this
.
timer
);
clearInterval
(
this
.
timer
);
...
@@ -112,12 +114,14 @@ Minder.Selection = kity.createClass( 'Selection', {
...
@@ -112,12 +114,14 @@ Minder.Selection = kity.createClass( 'Selection', {
state
=
state
?
''
:
'none'
;
state
=
state
?
''
:
'none'
;
},
400
);
},
400
);
}
}
return
this
;
return
this
;
},
},
isShow
:
function
(){
isShow
:
function
(){
return
this
.
_show
;
return
this
.
_show
;
},
},
isHide
:
function
(){
return
!
this
.
_show
;
},
setTextShape
:
function
(
text
)
{
setTextShape
:
function
(
text
)
{
if
(
!
text
)
{
if
(
!
text
)
{
this
.
text
=
new
kity
.
Text
();
this
.
text
=
new
kity
.
Text
();
...
...
src/module/history.js
View file @
02f04f4c
...
@@ -68,7 +68,9 @@ KityMinder.registerModule("HistoryModule", function() {
...
@@ -68,7 +68,9 @@ KityMinder.registerModule("HistoryModule", function() {
}
}
function
appendChildNode
(
parent
,
child
)
{
function
appendChildNode
(
parent
,
child
)
{
parent
.
appendChild
(
child
);
km
.
appendNode
(
child
,
parent
);
child
.
render
();
for
(
var
i
=
0
,
ci
;
ci
=
child
.
children
[
i
++
];)
{
for
(
var
i
=
0
,
ci
;
ci
=
child
.
children
[
i
++
];)
{
appendChildNode
(
child
,
ci
);
appendChildNode
(
child
,
ci
);
}
}
...
@@ -101,6 +103,7 @@ KityMinder.registerModule("HistoryModule", function() {
...
@@ -101,6 +103,7 @@ KityMinder.registerModule("HistoryModule", function() {
traverseNode
(
km
.
getRoot
(),
target
);
traverseNode
(
km
.
getRoot
(),
target
);
km
.
layout
();
km
.
layout
();
},
},
restore
:
function
()
{
restore
:
function
()
{
var
scene
=
this
.
list
[
this
.
index
];
var
scene
=
this
.
list
[
this
.
index
];
...
...
src/module/node.js
View file @
02f04f4c
...
@@ -30,7 +30,7 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
...
@@ -30,7 +30,7 @@ var AppendSiblingCommand = kity.createClass('AppendSiblingCommand', {
km
.
select
(
node
,
true
);
km
.
select
(
node
,
true
);
node
.
render
();
node
.
render
();
node
.
_lastLayoutTransform
=
sibling
.
_lastLayoutTransform
;
node
.
_lastLayoutTransform
=
sibling
.
_lastLayoutTransform
;
km
.
layout
(
300
0
);
km
.
layout
(
300
);
},
},
queryState
:
function
(
km
)
{
queryState
:
function
(
km
)
{
var
selectedNode
=
km
.
getSelectedNode
();
var
selectedNode
=
km
.
getSelectedNode
();
...
...
src/module/select.js
View file @
02f04f4c
...
@@ -29,7 +29,7 @@ KityMinder.registerModule('Select', function() {
...
@@ -29,7 +29,7 @@ KityMinder.registerModule('Select', function() {
startPosition
=
g
.
snapToSharp
(
e
.
getPosition
());
startPosition
=
g
.
snapToSharp
(
e
.
getPosition
());
},
},
selectMove
:
function
(
e
)
{
selectMove
:
function
(
e
)
{
if
(
minder
.
isTextEditStatus
()
)
{
if
(
minder
.
getStatus
()
==
'textedit'
)
{
return
;
return
;
}
}
if
(
!
startPosition
)
return
;
if
(
!
startPosition
)
return
;
...
@@ -95,7 +95,8 @@ KityMinder.registerModule('Select', function() {
...
@@ -95,7 +95,8 @@ KityMinder.registerModule('Select', function() {
var
lastDownNode
=
null
,
lastDownPosition
=
null
;
var
lastDownNode
=
null
,
lastDownPosition
=
null
;
return
{
return
{
'events'
:
{
'events'
:
{
'normal.mousedown textedit.mousedown'
:
function
(
e
)
{
'normal.mousedown textedit.mousedown inputready.mousedown'
:
function
(
e
)
{
var
downNode
=
e
.
getTargetNode
();
var
downNode
=
e
.
getTargetNode
();
// 没有点中节点:
// 没有点中节点:
...
@@ -127,8 +128,8 @@ KityMinder.registerModule('Select', function() {
...
@@ -127,8 +128,8 @@ KityMinder.registerModule('Select', function() {
lastDownPosition
=
e
.
getPosition
(
this
.
getRenderContainer
());
lastDownPosition
=
e
.
getPosition
(
this
.
getRenderContainer
());
}
}
},
},
'normal.mousemove textedit.mousemove'
:
marqueeActivator
.
selectMove
,
'normal.mousemove textedit.mousemove
inputready.mousemove
'
:
marqueeActivator
.
selectMove
,
'normal.mouseup textedit.mouseup'
:
function
(
e
)
{
'normal.mouseup textedit.mouseup
inputready.mouseup
'
:
function
(
e
)
{
var
upNode
=
e
.
getTargetNode
();
var
upNode
=
e
.
getTargetNode
();
// 如果 mouseup 发生在 lastDownNode 外,是无需理会的
// 如果 mouseup 发生在 lastDownNode 外,是无需理会的
...
...
src/module/text.js
View file @
02f04f4c
...
@@ -30,6 +30,11 @@ utils.extend(TextRenderer, {
...
@@ -30,6 +30,11 @@ utils.extend(TextRenderer, {
}
}
});
});
kity
.
extendClass
(
MinderNode
,{
getTextShape
:
function
(){
return
this
.
getRenderer
(
'TextRenderer'
).
getRenderShape
();
}
});
KityMinder
.
registerModule
(
'text'
,
{
KityMinder
.
registerModule
(
'text'
,
{
'renderers'
:
{
'renderers'
:
{
center
:
TextRenderer
center
:
TextRenderer
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment