File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,11 @@ html, body {
2929 margin : 1px ;
3030}
3131
32+ .cm-gutter , .cm-gutterElement {
33+ /* Disable this to have better experience of "swipe to select multiple lines" */
34+ pointer-events : none;
35+ }
36+
3237/* Markdown */
3338
3439.cm-md-header : not (.cm-md-frontMatter * ) {
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ import * as invisible from '../styling/nodes/invisible';
88import * as link from '../styling/nodes/link' ;
99
1010export function startObserving ( ) {
11- document . addEventListener ( 'click ' , event => {
11+ document . addEventListener ( 'mousedown ' , event => {
1212 selection . selectWholeLineIfNeeded ( event ) ;
1313 } ) ;
1414
Original file line number Diff line number Diff line change 11import { EditorView } from '@codemirror/view' ;
22import { EditorSelection , Line , SelectionRange } from '@codemirror/state' ;
3+ import { isReleaseMode } from '../../common/env' ;
34import { getClientRect } from '../../common/utils' ;
45
56import { InvisiblesBehavior } from '../../config' ;
@@ -67,8 +68,28 @@ export function selectedMainText(): string {
6768 */
6869export function selectWholeLineIfNeeded ( event : MouseEvent ) {
6970 const target = event . target ;
70- if ( target instanceof HTMLDivElement && target . classList . contains ( 'cm-gutterElement' ) ) {
71- selectWholeLineAt ( parseInt ( target . innerText ) ) ;
71+ if ( ! ( target instanceof HTMLDivElement ) || ! target . classList . contains ( 'cm-gutters' ) ) {
72+ return ;
73+ }
74+
75+ const gutterElements = [ ...target . querySelectorAll ( '.cm-gutterElement' ) ] ;
76+ if ( ! isReleaseMode ) {
77+ console . log ( `Found ${ gutterElements . length } gutter elements` ) ;
78+ }
79+
80+ // For a better experience of selecting multiple lines, ".cm-gutterElement" ignores user interactions,
81+ // we need to find the actual clicked gutter element manually.
82+ const actualElement = gutterElements . find ( element => {
83+ const rect = element . getBoundingClientRect ( ) ;
84+ if ( rect . top < event . clientY && rect . bottom > event . clientY ) {
85+ return element ;
86+ }
87+
88+ return undefined ;
89+ } ) as HTMLElement | undefined ;
90+
91+ if ( actualElement !== undefined ) {
92+ selectWholeLineAt ( parseInt ( actualElement . innerText ) ) ;
7293 }
7394}
7495
You can’t perform that action at this time.
0 commit comments