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
7e559721
Commit
7e559721
authored
Feb 14, 2014
by
campaign
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
by zhanyi
parent
02af05d8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
224 additions
and
22 deletions
+224
-22
dev.php
dist/dev.php
+1
-1
utils.js
src/adapter/utils.js
+0
-1
editor.js
src/module/editor.js
+32
-8
editor.receiver.js
src/module/editor.receiver.js
+79
-12
editor.selection.js
src/module/editor.selection.js
+112
-0
No files found.
dist/dev.php
View file @
7e559721
...
...
@@ -29,7 +29,7 @@ $dependency = Array(
,
'src/module/editor.js'
,
'src/module/editor.range.js'
,
'src/module/editor.receiver.js'
,
'src/module/editor.
cursor
.js'
,
'src/module/editor.
selection
.js'
,
'src/module/basestyle.js'
,
'src/module/font.js'
,
'src/module/zoom.js'
...
...
src/adapter/utils.js
View file @
7e559721
...
...
@@ -31,5 +31,4 @@ $.wordCountAdaptive = function( word, hasSuffix ) {
return
$
.
wordCountAdaptive
(
word
+
'...'
,
true
);
}
};
\ No newline at end of file
src/module/editor.js
View file @
7e559721
KityMinder
.
registerModule
(
"TextEditModule"
,
function
()
{
var
cursor
=
new
Minder
.
Cursor
();
var
sel
=
new
Minder
.
Selection
();
var
receiver
=
new
Minder
.
Receiver
(
this
);
var
range
=
new
Minder
.
Range
();
this
.
receiver
=
receiver
;
var
mouseDownStatus
=
false
;
var
oneTime
=
0
;
var
lastEvtPosition
,
dir
=
1
;
return
{
//插入光标
"init"
:
function
(){
this
.
getPaper
().
addShape
(
cursor
);
this
.
getPaper
().
addShape
(
sel
);
},
"events"
:
{
'beforemousedown'
:
function
(
e
){
cursor
.
setHide
();
sel
.
setHide
();
var
node
=
e
.
getTargetNode
();
if
(
node
){
var
textShape
=
node
.
getTextShape
();
textShape
.
setStyle
(
'cursor'
,
'default'
);
if
(
node
.
isSelected
()){
sel
.
collapse
();
node
.
getTextShape
().
setStyle
(
'cursor'
,
'text'
);
receiver
.
setTextEditStatus
(
true
)
.
set
Cursor
(
cursor
)
.
set
Selection
(
sel
)
.
setKityMinder
(
this
)
.
setMinderNode
(
node
)
.
setTextShape
(
textShape
)
.
setBaseOffset
()
.
setContainerStyle
()
.
set
Cursor
Height
()
.
set
Selection
Height
()
.
setCurrentIndex
(
e
.
getPosition
())
.
update
Cursor
()
.
update
Selection
()
.
setRange
(
range
);
mouseDownStatus
=
true
;
lastEvtPosition
=
e
.
getPosition
();
}
}
},
'mouseup'
:
function
(
e
){
mouseDownStatus
=
false
;
oneTime
=
0
;
},
'mousemove'
:
function
(
e
){
if
(
mouseDownStatus
){
var
offset
=
e
.
getPosition
();
dir
=
offset
.
x
>
lastEvtPosition
.
x
?
1
:
(
offset
.
x
<
lastEvtPosition
.
x
?
-
1
:
dir
);
receiver
.
updateSelectionByMousePosition
(
offset
,
dir
)
.
updateSelectionShow
(
dir
);
sel
.
stroke
(
'none'
,
0
);
lastEvtPosition
=
e
.
getPosition
();
}
},
'restoreScene'
:
function
(){
cursor
.
setHide
();
sel
.
setHide
();
},
'stopTextEdit'
:
function
(){
cursor
.
setHide
();
sel
.
setHide
();
}
}
...
...
src/module/editor.receiver.js
View file @
7e559721
...
...
@@ -2,7 +2,7 @@
Minder
.
Receiver
=
kity
.
createClass
(
'Receiver'
,{
clear
:
function
(){
this
.
container
.
innerHTML
=
''
;
this
.
cursor
.
setHide
();
this
.
selection
.
setHide
();
this
.
index
=
0
;
return
this
;
},
...
...
@@ -99,10 +99,10 @@ Minder.Receiver = kity.createClass('Receiver',{
this
.
setBaseOffset
();
this
.
updateTextData
();
this
.
updateIndex
();
this
.
update
Cursor
();
this
.
update
Selection
();
this
.
timer
=
setTimeout
(
function
(){
me
.
cursor
.
setShow
()
me
.
selection
.
setShow
()
},
500
);
return
true
;
}
...
...
@@ -115,21 +115,23 @@ Minder.Receiver = kity.createClass('Receiver',{
updateTextData
:
function
(){
this
.
textShape
.
textData
=
this
.
getTextOffsetData
();
},
set
Cursor
:
function
(
cursor
){
this
.
cursor
=
cursor
;
set
Selection
:
function
(
selection
){
this
.
selection
=
selection
;
return
this
;
},
updateCursor
:
function
(){
this
.
cursor
.
setShowHold
();
this
.
cursor
.
bringTop
();
updateSelection
:
function
(){
this
.
selection
.
setShowHold
();
this
.
selection
.
bringTop
();
//更新模拟选区的范围
this
.
selection
.
setStartOffset
(
this
.
index
).
collapse
(
true
);
if
(
this
.
index
==
this
.
textData
.
length
){
this
.
cursor
.
setPosition
({
this
.
selection
.
setPosition
({
x
:
this
.
textData
[
this
.
index
-
1
].
x
+
this
.
textData
[
this
.
index
-
1
].
width
,
y
:
this
.
textData
[
this
.
index
-
1
].
y
})
}
else
{
this
.
cursor
.
setPosition
(
this
.
textData
[
this
.
index
])
this
.
selection
.
setPosition
(
this
.
textData
[
this
.
index
])
}
return
this
;
},
...
...
@@ -199,8 +201,73 @@ Minder.Receiver = kity.createClass('Receiver',{
return
this
;
},
set
Cursor
Height
:
function
(){
this
.
cursor
.
setHeight
(
this
.
getTextShapeHeight
());
set
Selection
Height
:
function
(){
this
.
selection
.
setHeight
(
this
.
getTextShapeHeight
());
return
this
;
},
getIndexByMousePosition
:
function
(
offset
,
dir
){
var
me
=
this
;
var
currentIndex
;
var
hadChanged
=
false
;
utils
.
each
(
this
.
textData
,
function
(
i
,
v
){
//点击开始之前
if
(
i
==
0
&&
offset
.
x
<=
v
.
x
){
currentIndex
=
0
;
return
false
;
}
if
(
i
==
me
.
textData
.
length
-
1
&&
offset
.
x
>=
v
.
x
){
currentIndex
=
me
.
textData
.
length
;
return
false
;
}
if
(
offset
.
x
>=
v
.
x
&&
offset
.
x
<=
v
.
x
+
v
.
width
){
currentIndex
=
i
+
(
dir
==
-
1
?
0
:
1
);
return
false
;
}
});
return
currentIndex
;
},
updateSelectionByMousePosition
:
function
(
offset
,
dir
){
var
currentIndex
=
this
.
getIndexByMousePosition
(
offset
,
dir
);
if
(
currentIndex
==
0
||
currentIndex
==
this
.
textData
.
length
){
this
.
selection
.
setEndOffset
(
currentIndex
);
}
else
{
if
(
dir
==
-
1
&&
currentIndex
<
this
.
selection
.
startOffset
){
this
.
selection
.
setStartOffset
(
currentIndex
)
}
else
{
this
.
selection
.
setEndOffset
(
currentIndex
);
}
console
.
log
(
this
.
selection
.
startOffset
+
':'
+
this
.
selection
.
endOffset
)
console
.
log
(
this
.
selection
.
isCollapsed
)
}
return
this
;
},
updateSelectionShow
:
function
(
dir
){
var
startOffset
=
this
.
textData
[
this
.
selection
.
startOffset
],
endOffset
=
this
.
textData
[
this
.
selection
.
endOffset
],
width
=
0
;
if
(
this
.
selection
.
isCollapsed
){
this
.
selection
.
updateShow
(
startOffset
,
0
);
return
this
;
}
if
(
!
endOffset
){
var
lastOffset
=
this
.
textData
[
this
.
textData
.
length
-
1
];
width
=
lastOffset
.
x
-
startOffset
.
x
+
lastOffset
.
width
;
}
else
{
width
=
endOffset
.
x
-
startOffset
.
x
;
}
this
.
selection
.
updateShow
(
startOffset
,
width
);
return
this
;
},
updateNativeRange
:
function
(){
}
});
\ No newline at end of file
src/module/editor.
cursor
.js
→
src/module/editor.
selection
.js
View file @
7e559721
//模拟光标
Minder
.
Cursor
=
kity
.
createClass
(
'Cursor
'
,
{
base
:
kity
.
Line
,
Minder
.
Selection
=
kity
.
createClass
(
'Selection
'
,
{
base
:
kity
.
Rect
,
constructor
:
function
(
height
,
color
,
width
)
{
this
.
callBase
();
this
.
height
=
height
||
20
;
this
.
stroke
(
color
||
'blue'
,
width
||
1
);
this
.
width
=
1
;
this
.
fill
(
'#99C8FF'
);
this
.
setHide
();
this
.
timer
=
null
;
this
.
isCollapsed
=
true
;
this
.
startOffset
=
this
.
endOffset
=
0
;
this
.
setOpacity
(
0.5
)
},
collapse
:
function
(
toEnd
){
this
.
stroke
(
'blue'
,
1
);
this
.
width
=
1
;
this
.
isCollapsed
=
true
;
if
(
toEnd
){
this
.
startOffset
=
this
.
endOffset
}
else
{
this
.
endOffset
=
this
.
startOffset
;
}
return
this
;
},
setStartOffset
:
function
(
offset
){
this
.
startOffset
=
offset
;
var
tmpOffset
=
this
.
startOffset
;
if
(
this
.
startOffset
>
this
.
endOffset
){
this
.
startOffset
=
this
.
endOffset
;
this
.
endOffset
=
tmpOffset
;
}
else
if
(
this
.
startOffset
==
this
.
endOffset
){
this
.
collapse
();
return
this
;
}
this
.
isCollapsed
=
false
;
this
.
stroke
(
'none'
);
return
this
;
},
setEndOffset
:
function
(
offset
){
this
.
endOffset
=
offset
;
var
tmpOffset
=
this
.
endOffset
;
if
(
this
.
endOffset
<
this
.
startOffset
){
this
.
endOffset
=
this
.
startOffset
;
this
.
startOffset
=
tmpOffset
;
}
else
if
(
this
.
startOffset
==
this
.
endOffset
){
this
.
collapse
();
return
this
;
}
this
.
isCollapsed
=
false
;
this
.
stroke
(
'none'
);
return
this
;
},
updateShow
:
function
(
offset
,
width
){
this
.
setPosition
(
offset
).
setWidth
(
width
);
return
this
;
},
setPosition
:
function
(
offset
)
{
try
{
this
.
setPoint1
(
offset
.
x
,
offset
.
y
);
this
.
setPoint2
(
offset
.
x
,
offset
.
y
+
this
.
height
);
this
.
x
=
offset
.
x
;
this
.
y
=
offset
.
y
;
}
catch
(
e
)
{
debugger
console
.
log
(
e
)
}
return
this
;
return
this
.
update
();
},
setHeight
:
function
(
height
)
{
this
.
height
=
height
;
...
...
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