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
4290648c
Commit
4290648c
authored
11 years ago
by
Marijn Haverbeke
Browse files
Options
Downloads
Patches
Plain Diff
[markselection and activeline addons] Adjust to multi-selections
Issue #778
parent
31859376
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
addon/selection/active-line.js
+29
-15
29 additions, 15 deletions
addon/selection/active-line.js
addon/selection/mark-selection.js
+7
-7
7 additions, 7 deletions
addon/selection/mark-selection.js
with
36 additions
and
22 deletions
addon/selection/active-line.js
+
29
−
15
View file @
4290648c
...
...
@@ -12,34 +12,48 @@
CodeMirror
.
defineOption
(
"
styleActiveLine
"
,
false
,
function
(
cm
,
val
,
old
)
{
var
prev
=
old
&&
old
!=
CodeMirror
.
Init
;
if
(
val
&&
!
prev
)
{
updateActiveLine
(
cm
,
cm
.
getCursor
().
line
);
cm
.
state
.
activeLines
=
[];
updateActiveLines
(
cm
,
cm
.
listSelections
());
cm
.
on
(
"
beforeSelectionChange
"
,
selectionChange
);
}
else
if
(
!
val
&&
prev
)
{
cm
.
off
(
"
beforeSelectionChange
"
,
selectionChange
);
clearActiveLine
(
cm
);
delete
cm
.
state
.
activeLine
;
clearActiveLine
s
(
cm
);
delete
cm
.
state
.
activeLine
s
;
}
});
function
clearActiveLine
(
cm
)
{
if
(
"
activeLine
"
in
cm
.
state
)
{
cm
.
removeLineClass
(
cm
.
state
.
activeLine
,
"
wrap
"
,
WRAP_CLASS
);
cm
.
removeLineClass
(
cm
.
state
.
activeLine
,
"
background
"
,
BACK_CLASS
);
function
clearActiveLine
s
(
cm
)
{
for
(
var
i
=
0
;
i
<
cm
.
state
.
activeLines
.
length
;
i
++
)
{
cm
.
removeLineClass
(
cm
.
state
.
activeLine
s
[
i
]
,
"
wrap
"
,
WRAP_CLASS
);
cm
.
removeLineClass
(
cm
.
state
.
activeLine
s
[
i
]
,
"
background
"
,
BACK_CLASS
);
}
}
function
updateActiveLine
(
cm
,
selectedLine
)
{
var
line
=
cm
.
getLineHandleVisualStart
(
selectedLine
);
if
(
cm
.
state
.
activeLine
==
line
)
return
;
function
sameArray
(
a
,
b
)
{
if
(
a
.
length
!=
b
.
length
)
return
false
;
for
(
var
i
=
0
;
i
<
a
.
length
;
i
++
)
if
(
a
[
i
]
!=
b
[
i
])
return
false
;
return
true
;
}
function
updateActiveLines
(
cm
,
ranges
)
{
var
active
=
[];
for
(
var
i
=
0
;
i
<
ranges
.
length
;
i
++
)
{
var
line
=
cm
.
getLineHandleVisualStart
(
ranges
[
i
].
head
.
line
);
if
(
active
[
active
.
length
-
1
]
!=
line
)
active
.
push
(
line
);
}
if
(
sameArray
(
cm
.
state
.
activeLines
,
active
))
return
;
cm
.
operation
(
function
()
{
clearActiveLine
(
cm
);
cm
.
addLineClass
(
line
,
"
wrap
"
,
WRAP_CLASS
);
cm
.
addLineClass
(
line
,
"
background
"
,
BACK_CLASS
);
cm
.
state
.
activeLine
=
line
;
clearActiveLines
(
cm
);
for
(
var
i
=
0
;
i
<
active
.
length
;
i
++
)
{
cm
.
addLineClass
(
active
[
i
],
"
wrap
"
,
WRAP_CLASS
);
cm
.
addLineClass
(
active
[
i
],
"
background
"
,
BACK_CLASS
);
}
cm
.
state
.
activeLines
=
active
;
});
}
function
selectionChange
(
cm
,
sel
)
{
updateActiveLine
(
cm
,
sel
.
head
.
line
);
updateActiveLine
s
(
cm
,
sel
.
ranges
);
}
})();
This diff is collapsed.
Click to expand it.
addon/selection/mark-selection.js
+
7
−
7
View file @
4290648c
...
...
@@ -34,10 +34,7 @@
var
CHUNK_SIZE
=
8
;
var
Pos
=
CodeMirror
.
Pos
;
function
cmp
(
pos1
,
pos2
)
{
return
pos1
.
line
-
pos2
.
line
||
pos1
.
ch
-
pos2
.
ch
;
}
var
cmp
=
CodeMirror
.
cmpPos
;
function
coverRange
(
cm
,
from
,
to
,
addAt
)
{
if
(
cmp
(
from
,
to
)
==
0
)
return
;
...
...
@@ -63,13 +60,16 @@
function
reset
(
cm
)
{
clear
(
cm
);
var
from
=
cm
.
getCursor
(
"
start
"
),
to
=
cm
.
getCursor
(
"
end
"
);
coverRange
(
cm
,
from
,
to
);
var
ranges
=
cm
.
listSelections
();
for
(
var
i
=
0
;
i
<
ranges
.
length
;
i
++
)
coverRange
(
cm
,
ranges
[
i
].
from
(),
ranges
[
i
].
to
());
}
function
update
(
cm
)
{
if
(
!
cm
.
somethingSelected
())
return
clear
(
cm
);
if
(
cm
.
listSelections
().
length
>
1
)
return
reset
(
cm
);
var
from
=
cm
.
getCursor
(
"
start
"
),
to
=
cm
.
getCursor
(
"
end
"
);
if
(
cmp
(
from
,
to
)
==
0
)
return
clear
(
cm
);
var
array
=
cm
.
state
.
markedSelection
;
if
(
!
array
.
length
)
return
coverRange
(
cm
,
from
,
to
);
...
...
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