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
8ca09be7
Commit
8ca09be7
authored
11 years ago
by
Marijn Haverbeke
Browse files
Options
Downloads
Patches
Plain Diff
[comment & continuecomment addons] Make multi-selection aware
Issue #778
parent
e0127458
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/comment/comment.js
+15
-2
15 additions, 2 deletions
addon/comment/comment.js
addon/comment/continuecomment.js
+38
-30
38 additions, 30 deletions
addon/comment/continuecomment.js
with
53 additions
and
32 deletions
addon/comment/comment.js
+
15
−
2
View file @
8ca09be7
...
...
@@ -11,8 +11,21 @@
}
CodeMirror
.
commands
.
toggleComment
=
function
(
cm
)
{
var
from
=
cm
.
getCursor
(
"
start
"
),
to
=
cm
.
getCursor
(
"
end
"
);
cm
.
uncomment
(
from
,
to
)
||
cm
.
lineComment
(
from
,
to
);
var
minLine
=
Infinity
,
ranges
=
cm
.
listSelections
(),
mode
=
null
;
for
(
var
i
=
ranges
.
length
-
1
;
i
>=
0
;
i
--
)
{
var
from
=
ranges
[
i
].
from
(),
to
=
ranges
[
i
].
to
();
if
(
from
.
line
>=
minLine
)
continue
;
if
(
to
.
line
>=
minLine
)
to
=
Pos
(
minLine
,
0
);
minLine
=
from
.
line
;
if
(
mode
==
null
)
{
if
(
cm
.
uncomment
(
from
,
to
))
mode
=
"
un
"
;
else
{
cm
.
lineComment
(
from
,
to
);
mode
=
"
line
"
;
}
}
else
if
(
mode
==
"
un
"
)
{
cm
.
uncomment
(
from
,
to
);
}
else
{
cm
.
lineComment
(
from
,
to
);
}
}
};
CodeMirror
.
defineExtension
(
"
lineComment
"
,
function
(
from
,
to
,
options
)
{
...
...
This diff is collapsed.
Click to expand it.
addon/comment/continuecomment.js
+
38
−
30
View file @
8ca09be7
...
...
@@ -4,42 +4,50 @@
CodeMirror
.
extendMode
(
modes
[
i
],
{
blockCommentContinue
:
"
*
"
});
function
continueComment
(
cm
)
{
var
pos
=
cm
.
getCursor
(),
token
=
cm
.
getTokenAt
(
pos
);
if
(
token
.
type
!=
"
comment
"
||
cm
.
getOption
(
"
disableInput
"
))
return
CodeMirror
.
Pass
;
var
mode
=
CodeMirror
.
innerMode
(
cm
.
getMode
(),
token
.
state
).
mode
;
if
(
cm
.
getOption
(
"
disableInput
"
))
return
CodeMirror
.
Pass
;
var
ranges
=
cm
.
listSelections
(),
mode
,
inserts
=
[];
for
(
var
i
=
0
;
i
<
ranges
.
length
;
i
++
)
{
var
pos
=
ranges
[
i
].
head
,
token
=
cm
.
getTokenAt
(
pos
);
if
(
token
.
type
!=
"
comment
"
)
return
CodeMirror
.
Pass
;
var
modeHere
=
CodeMirror
.
innerMode
(
cm
.
getMode
(),
token
.
state
).
mode
;
if
(
!
mode
)
mode
=
modeHere
;
else
if
(
mode
!=
modeHere
)
return
CodeMirror
.
Pass
;
var
insert
;
if
(
mode
.
blockCommentStart
&&
mode
.
blockCommentContinue
)
{
var
end
=
token
.
string
.
indexOf
(
mode
.
blockCommentEnd
);
var
full
=
cm
.
getRange
(
CodeMirror
.
Pos
(
pos
.
line
,
0
),
CodeMirror
.
Pos
(
pos
.
line
,
token
.
end
)),
found
;
if
(
end
!=
-
1
&&
end
==
token
.
string
.
length
-
mode
.
blockCommentEnd
.
length
)
{
// Comment ended, don't continue it
}
else
if
(
token
.
string
.
indexOf
(
mode
.
blockCommentStart
)
==
0
)
{
insert
=
full
.
slice
(
0
,
token
.
start
);
if
(
!
/^
\s
*$/
.
test
(
insert
))
{
insert
=
""
;
for
(
var
i
=
0
;
i
<
token
.
start
;
++
i
)
insert
+=
"
"
;
var
insert
=
null
;
if
(
mode
.
blockCommentStart
&&
mode
.
blockCommentContinue
)
{
var
end
=
token
.
string
.
indexOf
(
mode
.
blockCommentEnd
);
var
full
=
cm
.
getRange
(
CodeMirror
.
Pos
(
pos
.
line
,
0
),
CodeMirror
.
Pos
(
pos
.
line
,
token
.
end
)),
found
;
if
(
end
!=
-
1
&&
end
==
token
.
string
.
length
-
mode
.
blockCommentEnd
.
length
)
{
// Comment ended, don't continue it
}
else
if
(
token
.
string
.
indexOf
(
mode
.
blockCommentStart
)
==
0
)
{
insert
=
full
.
slice
(
0
,
token
.
start
);
if
(
!
/^
\s
*$/
.
test
(
insert
))
{
insert
=
""
;
for
(
var
i
=
0
;
i
<
token
.
start
;
++
i
)
insert
+=
"
"
;
}
}
else
if
((
found
=
full
.
indexOf
(
mode
.
blockCommentContinue
))
!=
-
1
&&
found
+
mode
.
blockCommentContinue
.
length
>
token
.
start
&&
/^
\s
*$/
.
test
(
full
.
slice
(
0
,
found
)))
{
insert
=
full
.
slice
(
0
,
found
);
}
}
else
if
((
found
=
full
.
indexOf
(
mode
.
blockCommentContinue
))
!=
-
1
&&
found
+
mode
.
blockCommentContinue
.
length
>
token
.
start
&&
/^
\s
*$/
.
test
(
full
.
slice
(
0
,
found
)))
{
insert
=
full
.
slice
(
0
,
found
);
if
(
insert
!=
null
)
insert
+=
mode
.
blockCommentContinue
;
}
if
(
insert
!=
null
)
insert
+=
mode
.
blockCommentContinue
;
}
if
(
insert
==
null
&&
mode
.
lineComment
)
{
var
line
=
cm
.
getLine
(
pos
.
line
),
found
=
line
.
indexOf
(
mode
.
lineComment
);
if
(
found
>
-
1
)
{
insert
=
line
.
slice
(
0
,
found
);
if
(
/
\S
/
.
test
(
insert
))
insert
=
null
;
else
insert
+=
mode
.
lineComment
+
line
.
slice
(
found
+
mode
.
lineComment
.
length
).
match
(
/^
\s
*/
)[
0
];
if
(
insert
==
null
&&
mode
.
lineComment
)
{
var
line
=
cm
.
getLine
(
pos
.
line
),
found
=
line
.
indexOf
(
mode
.
lineComment
);
if
(
found
>
-
1
)
{
insert
=
line
.
slice
(
0
,
found
);
if
(
/
\S
/
.
test
(
insert
))
insert
=
null
;
else
insert
+=
mode
.
lineComment
+
line
.
slice
(
found
+
mode
.
lineComment
.
length
).
match
(
/^
\s
*/
)[
0
];
}
}
if
(
insert
==
null
)
return
CodeMirror
.
Pass
;
inserts
[
i
]
=
"
\n
"
+
insert
;
}
if
(
insert
!=
null
)
cm
.
replaceSelection
(
"
\n
"
+
insert
,
"
end
"
);
else
return
CodeMirror
.
Pass
;
cm
.
operation
(
function
()
{
for
(
var
i
=
ranges
.
length
-
1
;
i
>=
0
;
i
--
)
cm
.
replaceRange
(
inserts
[
i
],
ranges
[
i
].
from
(),
ranges
[
i
].
to
(),
"
+insert
"
);
})
;
}
CodeMirror
.
defineOption
(
"
continueComments
"
,
null
,
function
(
cm
,
val
,
prev
)
{
...
...
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