Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CodeMirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moritz Aurel Pascal Schubotz
CodeMirror
Commits
3842167f
Commit
3842167f
authored
8 years ago
by
Marijn Haverbeke
Browse files
Options
Downloads
Patches
Plain Diff
Add first contenteditable tests
parent
bad02ce6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/input/ContentEditableInput.js
+8
-6
8 additions, 6 deletions
src/input/ContentEditableInput.js
test/contenteditable_test.js
+68
-0
68 additions, 0 deletions
test/contenteditable_test.js
test/index.html
+1
-0
1 addition, 0 deletions
test/index.html
with
77 additions
and
6 deletions
src/input/ContentEditableInput.js
+
8
−
6
View file @
3842167f
...
...
@@ -34,9 +34,7 @@ export default class ContentEditableInput {
on
(
div
,
"
paste
"
,
e
=>
{
if
(
signalDOMEvent
(
cm
,
e
)
||
handlePaste
(
e
,
cm
))
return
// IE doesn't fire input events, so we schedule a read for the pasted content in this way
if
(
ie_version
<=
11
)
setTimeout
(
operation
(
cm
,
()
=>
{
if
(
!
input
.
pollContent
())
regChange
(
cm
)
}),
20
)
if
(
ie_version
<=
11
)
setTimeout
(
operation
(
cm
,
()
=>
this
.
updateFromDOM
()),
20
)
})
on
(
div
,
"
compositionstart
"
,
e
=>
{
...
...
@@ -303,7 +301,7 @@ export default class ContentEditableInput {
if
(
!
this
.
composing
)
return
clearTimeout
(
this
.
readDOMTimeout
)
this
.
composing
=
null
if
(
!
this
.
pollContent
())
regChange
(
this
.
cm
)
this
.
updateFromDOM
(
)
this
.
div
.
blur
()
this
.
div
.
focus
()
}
...
...
@@ -315,11 +313,15 @@ export default class ContentEditableInput {
if
(
this
.
composing
.
done
)
this
.
composing
=
null
else
return
}
if
(
this
.
cm
.
isReadOnly
()
||
!
this
.
pollContent
())
runInOp
(
this
.
cm
,
()
=>
regChange
(
this
.
cm
))
this
.
updateFromDOM
()
},
80
)
}
updateFromDOM
()
{
if
(
this
.
cm
.
isReadOnly
()
||
!
this
.
pollContent
())
runInOp
(
this
.
cm
,
()
=>
regChange
(
this
.
cm
))
}
setUneditable
(
node
)
{
node
.
contentEditable
=
"
false
"
}
...
...
This diff is collapsed.
Click to expand it.
test/contenteditable_test.js
0 → 100644
+
68
−
0
View file @
3842167f
(
function
()
{
"
use strict
"
;
namespace
=
"
contenteditable_
"
;
var
Pos
=
CodeMirror
.
Pos
function
findTextNode
(
dom
,
text
)
{
if
(
dom
instanceof
CodeMirror
)
dom
=
dom
.
getInputField
()
if
(
dom
.
nodeType
==
1
)
{
for
(
var
ch
=
dom
.
firstChild
;
ch
;
ch
=
ch
.
nextSibling
)
{
var
found
=
findTextNode
(
ch
,
text
)
if
(
found
)
return
found
}
}
else
if
(
dom
.
nodeType
==
3
&&
dom
.
nodeValue
==
text
)
{
return
dom
}
}
function
lineElt
(
node
)
{
for
(;;)
{
var
parent
=
node
.
parentNode
if
(
/CodeMirror-code/
.
test
(
parent
.
className
))
return
node
node
=
parent
}
}
testCM
(
"
insert_text
"
,
function
(
cm
)
{
findTextNode
(
cm
,
"
foobar
"
).
nodeValue
=
"
foo bar
"
cm
.
display
.
input
.
updateFromDOM
()
eq
(
cm
.
getValue
(),
"
foo bar
"
)
},
{
inputStyle
:
"
contenteditable
"
,
value
:
"
foobar
"
})
testCM
(
"
split_line
"
,
function
(
cm
)
{
cm
.
setSelection
(
Pos
(
2
,
3
))
var
node
=
findTextNode
(
cm
,
"
foobar
"
)
node
.
nodeValue
=
"
foo
"
var
lineNode
=
lineElt
(
node
)
lineNode
.
parentNode
.
insertBefore
(
document
.
createElement
(
"
pre
"
),
lineNode
.
nextSibling
).
textContent
=
"
bar
"
cm
.
display
.
input
.
updateFromDOM
()
eq
(
cm
.
getValue
(),
"
one
\n
two
\n
foo
\n
bar
\n
three
\n
four
\n
"
)
},
{
inputStyle
:
"
contenteditable
"
,
value
:
"
one
\n
two
\n
foobar
\n
three
\n
four
\n
"
})
testCM
(
"
join_line
"
,
function
(
cm
)
{
cm
.
setSelection
(
Pos
(
2
,
3
))
var
node
=
findTextNode
(
cm
,
"
foo
"
)
node
.
nodeValue
=
"
foobar
"
var
lineNode
=
lineElt
(
node
)
lineNode
.
parentNode
.
removeChild
(
lineNode
.
nextSibling
)
cm
.
display
.
input
.
updateFromDOM
()
eq
(
cm
.
getValue
(),
"
one
\n
two
\n
foobar
\n
three
\n
four
\n
"
)
},
{
inputStyle
:
"
contenteditable
"
,
value
:
"
one
\n
two
\n
foo
\n
bar
\n
three
\n
four
\n
"
})
testCM
(
"
delete_multiple
"
,
function
(
cm
)
{
cm
.
setSelection
(
Pos
(
1
,
3
),
Pos
(
4
,
0
))
var
text
=
findTextNode
(
cm
,
"
two
"
),
startLine
=
lineElt
(
text
)
for
(
var
i
=
0
;
i
<
3
;
i
++
)
startLine
.
parentNode
.
removeChild
(
startLine
.
nextSibling
)
text
.
nodeValue
=
"
twothree
"
cm
.
display
.
input
.
updateFromDOM
()
eq
(
cm
.
getValue
(),
"
one
\n
twothree
\n
four
\n
"
)
},
{
inputStyle
:
"
contenteditable
"
,
value
:
"
one
\n
two
\n
foo
\n
bar
\n
three
\n
four
\n
"
})
testCM
(
"
force_redraw
"
,
function
(
cm
)
{
findTextNode
(
cm
,
"
foo
"
).
parentNode
.
appendChild
(
document
.
createElement
(
"
hr
"
)).
className
=
"
inserted
"
cm
.
display
.
input
.
updateFromDOM
()
eq
(
byClassName
(
cm
.
getInputField
(),
"
inserted
"
).
length
,
0
)
},
{
inputStyle
:
"
contenteditable
"
,
value
:
"
foo
"
})
})();
This diff is collapsed.
Click to expand it.
test/index.html
+
1
−
0
View file @
3842167f
...
...
@@ -103,6 +103,7 @@
<script
src=
"test.js"
></script>
<script
src=
"doc_test.js"
></script>
<script
src=
"multi_test.js"
></script>
<script
src=
"contenteditable_test.js"
></script>
<script
src=
"scroll_test.js"
></script>
<script
src=
"comment_test.js"
></script>
<script
src=
"search_test.js"
></script>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment