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
ead205d7
Commit
ead205d7
authored
May 14, 2014
by
campaign
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
改进history的性能
parent
f8800cc4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
140 additions
and
60 deletions
+140
-60
node.js
src/core/node.js
+9
-3
editor.js
src/module/editor.js
+36
-7
editor.receiver.js
src/module/editor.receiver.js
+17
-19
history.js
src/module/history.js
+77
-31
layout.default.js
src/module/layout.default.js
+1
-0
No files found.
src/core/node.js
View file @
ead205d7
...
...
@@ -299,8 +299,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
return
false
;
}
}
);
if
(
textShape
===
undefined
)
debugger
return
textShape
;
},
isSelected
:
function
()
{
...
...
@@ -318,7 +317,7 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
setTmpData
:
function
(
a
,
v
)
{
var
me
=
this
;
if
(
utils
.
isObject
(
a
)
)
{
utils
.
each
(
a
,
function
(
val
,
key
)
{
utils
.
each
(
a
,
function
(
key
,
val
)
{
me
.
setTmpData
(
key
,
val
)
}
)
}
...
...
@@ -333,5 +332,12 @@ var MinderNode = KityMinder.MinderNode = kity.createClass( "MinderNode", {
return
this
.
tmpData
;
}
return
this
.
tmpData
[
a
]
},
setValue
:
function
(
node
){
this
.
data
=
{};
this
.
setData
(
utils
.
clonePlainObject
(
node
.
getData
()));
this
.
tmpData
=
{};
this
.
setTmpData
(
utils
.
clonePlainObject
(
node
.
getTmpData
()));
return
this
;
}
}
);
\ No newline at end of file
src/module/editor.js
View file @
ead205d7
...
...
@@ -106,11 +106,15 @@ KityMinder.registerModule( "TextEditModule", function () {
var
node
=
this
.
getSelectedNode
();
if
(
node
){
if
(
this
.
isSingleSelect
()
&&
node
.
isSelected
())
{
var
keyCode
=
e
.
originEvent
.
keyCode
;
if
(
!
keymap
.
notContentInput
[
keyCode
]
&&
range
.
nativeSel
.
rangeCount
!=
0
){
var
orgEvt
=
e
.
originEvent
,
keyCode
=
orgEvt
.
keyCode
;
if
(
!
keymap
.
notContentInput
[
keyCode
]
&&
range
.
nativeSel
.
rangeCount
!=
0
&&
!
orgEvt
.
ctrlKey
&&
!
orgEvt
.
metaKey
&&
!
orgEvt
.
shiftKey
&&
!
orgEvt
.
altKey
){
var
nativeRange
=
range
.
nativeSel
.
getRangeAt
(
0
);
if
(
nativeRange
&&
(
nativeRange
.
startContainer
===
receiver
.
container
||
receiver
.
container
.
contains
(
nativeRange
.
startContainer
)))
km
.
setStatus
(
'textedit'
)
if
(
nativeRange
&&
(
nativeRange
.
startContainer
===
receiver
.
container
||
receiver
.
container
.
contains
(
nativeRange
.
startContainer
))){
km
.
setStatus
(
'textedit'
);
km
.
fire
(
'saveScene'
);
}
}
}
}
...
...
@@ -120,8 +124,10 @@ KityMinder.registerModule( "TextEditModule", function () {
var
node
=
this
.
getSelectedNode
();
if
(
node
){
if
(
this
.
isSingleSelect
()
&&
node
.
isSelected
())
{
var
keyCode
=
e
.
originEvent
.
keyCode
;
if
(
keymap
.
isSelectedNodeKey
[
keyCode
]
&&
km
.
getStatus
()
!=
'textedit'
){
var
orgEvt
=
e
.
originEvent
,
keyCode
=
orgEvt
.
keyCode
;
if
(
keymap
.
isSelectedNodeKey
[
keyCode
]
&&
km
.
getStatus
()
!=
'textedit'
&&
!
orgEvt
.
ctrlKey
&&
!
orgEvt
.
metaKey
&&
!
orgEvt
.
shiftKey
&&
!
orgEvt
.
altKey
){
//准备输入状态
var
textShape
=
node
.
getTextShape
();
...
...
@@ -225,7 +231,30 @@ KityMinder.registerModule( "TextEditModule", function () {
}
},
'restoreScene'
:
function
(){
var
node
=
this
.
getSelectedNode
();
if
(
node
&&
this
.
isSingleSelect
()){
var
textShape
=
node
.
getTextShape
();
sel
.
setHide
();
sel
.
setStartOffset
(
0
);
sel
.
setEndOffset
(
textShape
.
getContent
().
length
);
receiver
.
setTextEditStatus
(
true
)
.
setSelection
(
sel
)
.
setKityMinder
(
this
)
.
setMinderNode
(
node
)
.
setTextShape
(
textShape
)
.
setRange
(
range
)
.
setBaseOffset
()
.
setContainerStyle
()
.
setSelectionHeight
()
.
setContainerTxt
(
textShape
.
getContent
())
.
updateRange
(
range
).
setTextEditStatus
(
true
);
sel
.
setData
(
'relatedNode'
,
node
);
}
else
{
receiver
.
clear
()
}
},
'stopTextEdit'
:
function
(){
sel
.
setHide
();
...
...
src/module/editor.receiver.js
View file @
ead205d7
...
...
@@ -95,7 +95,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
if
(
browser
.
gecko
&&
/
\s
$/
.
test
(
text
)
)
{
text
+=
"
\
u200b"
;
}
me
.
textShape
.
setContent
(
text
);
me
.
setContainerStyle
();
me
.
minderNode
.
setText
(
text
);
if
(
text
.
length
==
0
)
{
...
...
@@ -136,11 +136,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
e
.
preventDefault
();
return
;
break
;
case
keymap
.
Shift
:
case
keymap
.
Control
:
case
keymap
.
Alt
:
case
keymap
.
Cmd
:
return
;
}
if
(
e
.
originEvent
.
ctrlKey
||
e
.
originEvent
.
metaKey
)
{
...
...
@@ -167,19 +163,21 @@ Minder.Receiver = kity.createClass( 'Receiver', {
}
isTypeText
=
true
;
if
(
!
orgEvt
.
ctrlKey
&&
!
orgEvt
.
metaKey
&&
!
orgEvt
.
shiftKey
&&
!
orgEvt
.
altKey
){
setTextToContainer
();
}
break
;
case
'keypress'
:
if
(
isTypeText
)
// setTextToContainer();
isKeypress
=
true
;
break
;
case
'beforekeyup'
:
switch
(
keyCode
)
{
case
keymap
.
Enter
:
case
keymap
.
Tab
:
...
...
@@ -195,7 +193,7 @@ Minder.Receiver = kity.createClass( 'Receiver', {
}
if
(
!
isKeypress
)
{
if
(
!
isKeypress
&&
!
orgEvt
.
ctrlKey
&&
!
orgEvt
.
metaKey
&&
!
orgEvt
.
shiftKey
&&
!
orgEvt
.
altKey
)
{
setTextToContainer
();
}
return
true
;
...
...
src/module/history.js
View file @
ead205d7
...
...
@@ -26,6 +26,9 @@ KityMinder.registerModule( "HistoryModule", function () {
},
undo
:
function
()
{
if
(
this
.
hasUndo
)
{
// if(this.km.getStatus() == 'textedit'){
// return this.restore(this.index);
// }
if
(
!
this
.
list
[
this
.
index
-
1
]
&&
this
.
list
.
length
==
1
)
{
this
.
reset
();
return
;
...
...
@@ -36,7 +39,7 @@ KityMinder.registerModule( "HistoryModule", function () {
return
this
.
restore
(
0
);
}
}
this
.
restore
(
--
this
.
index
);
this
.
restore
(
--
this
.
index
);
}
},
redo
:
function
()
{
...
...
@@ -44,19 +47,62 @@ KityMinder.registerModule( "HistoryModule", function () {
while
(
this
.
list
[
this
.
index
].
equals
(
this
.
list
[
this
.
index
+
1
]
)
)
{
this
.
index
++
;
if
(
this
.
index
==
this
.
list
.
length
-
1
)
{
return
this
.
restore
(
this
.
index
);
return
this
.
restore
(
this
.
index
);
}
}
this
.
restore
(
++
this
.
index
);
this
.
restore
(
++
this
.
index
);
}
},
restore
:
function
()
{
var
scene
=
this
.
list
[
this
.
index
];
partialRenewal
:
function
(
target
){
function
compareNode
(
source
,
target
){
if
(
source
.
getText
()
!=
target
.
getText
()){
return
false
;
}
if
(
utils
.
compareObject
(
source
.
getData
(),
target
.
getData
()
)
===
false
)
{
return
false
;
}
if
(
utils
.
compareObject
(
source
.
getTmpData
(),
target
.
getTmpData
()
)
===
false
)
{
return
false
;
}
return
true
;
}
this
.
km
.
setRoot
(
scene
.
cloneData
()
);
this
.
km
.
removeAllSelectedNodes
();
this
.
km
.
initStyle
();
function
appendChildNode
(
parent
,
child
){
km
.
appendChildNode
(
parent
,
child
);
for
(
var
i
=
0
,
ci
;
ci
=
child
.
children
[
i
++
];){
appendChildNode
(
child
,
ci
)
}
}
function
traverseNode
(
srcNode
,
tagNode
){
if
(
compareNode
(
srcNode
,
tagNode
)
===
false
){
km
.
updateLayout
(
srcNode
.
setValue
(
tagNode
));
if
(
srcNode
.
isSelected
()){
km
.
select
(
srcNode
)
}
else
{
km
.
removeSelectedNodes
(
srcNode
)
}
}
for
(
var
i
=
0
,
j
=
0
,
si
,
tj
;
(
si
=
srcNode
.
children
[
i
]
,
tj
=
tagNode
.
children
[
j
],
si
||
tj
);
i
++
,
j
++
)
{
if
(
si
&&
!
tj
){
i
--
;
km
.
removeNode
(
si
)
}
else
if
(
!
si
&&
tj
){
j
--
;
appendChildNode
(
srcNode
,
tj
)
}
else
{
traverseNode
(
si
,
tj
)
}
}
}
traverseNode
(
km
.
getRoot
(),
target
)
},
restore
:
function
()
{
var
scene
=
this
.
list
[
this
.
index
];
this
.
partialRenewal
(
scene
.
cloneData
());
this
.
update
();
this
.
km
.
fire
(
'restoreScene'
);
this
.
km
.
fire
(
'contentChange'
);
...
...
@@ -82,7 +128,7 @@ KityMinder.registerModule( "HistoryModule", function () {
},
update
:
function
()
{
this
.
hasRedo
=
!!
this
.
list
[
this
.
index
+
1
];
this
.
hasUndo
=
!!
this
.
list
[
this
.
index
-
1
];
this
.
hasUndo
=
!!
this
.
list
[
this
.
index
-
1
]
//|| this.km.getStatus() == 'textedit'
;
},
reset
:
function
()
{
this
.
list
=
[];
...
...
@@ -161,28 +207,28 @@ KityMinder.registerModule( "HistoryModule", function () {
this
.
select
(
node
)
}
},
"keydown"
:
function
(
e
)
{
var
orgEvt
=
e
.
originEvent
;
var
keyCode
=
orgEvt
.
keyCode
||
orgEvt
.
which
;
if
(
!
keys
[
keyCode
]
&&
!
orgEvt
.
ctrlKey
&&
!
orgEvt
.
metaKey
&&
!
orgEvt
.
shiftKey
&&
!
orgEvt
.
altKey
)
{
if
(
km
.
historyManager
.
list
.
length
==
0
)
{
km
.
historyManager
.
saveScene
();
}
clearTimeout
(
saveSceneTimer
);
saveSceneTimer
=
setTimeout
(
function
()
{
km
.
historyManager
.
saveScene
();
},
200
);
lastKeyCode
=
keyCode
;
keycont
++
;
if
(
keycont
>=
km
.
getOptions
(
'maxInputCount'
)
)
{
km
.
historyManager
.
saveScene
()
}
}
},
//
"keydown": function ( e ) {
//
var orgEvt = e.originEvent;
//
var keyCode = orgEvt.keyCode || orgEvt.which;
//
if ( !keys[ keyCode ] && !orgEvt.ctrlKey && !orgEvt.metaKey && !orgEvt.shiftKey && !orgEvt.altKey ) {
//
//
//
if ( km.historyManager.list.length == 0 ) {
//
km.historyManager.saveScene();
//
}
//
clearTimeout( saveSceneTimer );
//
//
saveSceneTimer = setTimeout( function () {
//
km.historyManager.saveScene();
//
}, 200 );
//
//
lastKeyCode = keyCode;
//
keycont++;
//
if ( keycont >= km.getOptions( 'maxInputCount' ) ) {
//
km.historyManager.saveScene()
//
}
//
}
//
},
"import"
:
function
()
{
this
.
historyManager
.
reset
()
}
...
...
src/module/layout.default.js
View file @
ead205d7
...
...
@@ -712,6 +712,7 @@ KityMinder.registerModule( "LayoutDefault", function () {
this
.
appendChildNode
(
parent
,
node
,
focus
,
sibling
);
},
removeNode
:
function
(
nodes
)
{
nodes
=
utils
.
isArray
(
nodes
)
?
nodes
:
[
nodes
];
while
(
nodes
.
length
!==
0
)
{
var
parent
=
nodes
[
0
].
getParent
();
if
(
!
parent
)
{
...
...
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