File tree Expand file tree Collapse file tree
components/material/OnlineList Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import assert from 'node:assert/strict'
2+
3+ import { shouldCopyListTextOnContextMenu } from '../../src/renderer/utils/listContextMenu.mjs'
4+
5+ const run = ( name , fn ) => {
6+ try {
7+ fn ( )
8+ console . log ( `PASS ${ name } ` )
9+ } catch ( error ) {
10+ console . error ( `FAIL ${ name } ` )
11+ throw error
12+ }
13+ }
14+
15+ run ( 'does not hijack row menu when right-clicking selectable text without an active selection' , ( ) => {
16+ assert . equal ( shouldCopyListTextOnContextMenu ( {
17+ isSelectTextTarget : true ,
18+ selectionText : '' ,
19+ } ) , false )
20+ } )
21+
22+ run ( 'keeps text copy behavior when right-clicking selected text' , ( ) => {
23+ assert . equal ( shouldCopyListTextOnContextMenu ( {
24+ isSelectTextTarget : true ,
25+ selectionText : 'Song Name' ,
26+ } ) , true )
27+ } )
28+
29+ run ( 'ignores non-select targets' , ( ) => {
30+ assert . equal ( shouldCopyListTextOnContextMenu ( {
31+ isSelectTextTarget : false ,
32+ selectionText : 'Song Name' ,
33+ } ) , false )
34+ } )
Original file line number Diff line number Diff line change 102102import { clipboardWriteText } from ' @common/utils/electron'
103103import { assertApiSupport } from ' @renderer/store/utils'
104104import { ref } from ' @common/utils/vueTools'
105+ import { shouldCopyListTextOnContextMenu , formatListSelectionText } from ' @renderer/utils/listContextMenu.mjs'
105106import useList from ' ./useList'
106107import useMenu from ' ./useMenu'
107108import usePlay from ' ./usePlay'
@@ -218,14 +219,17 @@ export default {
218219 menuClick (action, index)
219220 }
220221 const handleListRightClick = (event ) => {
221- if (! event .target .classList .contains (' select' )) return
222+ const selectionText = window .getSelection ().toString ()
223+ if (! shouldCopyListTextOnContextMenu ({
224+ isSelectTextTarget: event .target .classList .contains (' select' ),
225+ selectionText,
226+ })) return
222227 event .stopImmediatePropagation ()
223228 let classList = dom_listContent .value .classList
224229 classList .add (' copying' )
225230 window .requestAnimationFrame (() => {
226- let str = window .getSelection ().toString ()
227231 classList .remove (' copying' )
228- str = str . split ( / \n\n / ). map ( s => s . replace ( / \n / g , ' ' )). join ( ' \n ' ). trim ( )
232+ let str = formatListSelectionText ( window . getSelection (). toString () )
229233 if (! str .length ) return
230234 clipboardWriteText (str)
231235 })
Original file line number Diff line number Diff line change 1+ export const shouldCopyListTextOnContextMenu = ( {
2+ isSelectTextTarget,
3+ selectionText,
4+ } ) => {
5+ return isSelectTextTarget && ! ! selectionText . trim ( )
6+ }
7+
8+ export const formatListSelectionText = ( selectionText ) => {
9+ return selectionText
10+ . split ( / \n \n / )
11+ . map ( text => text . replace ( / \n / g, ' ' ) )
12+ . join ( '\n' )
13+ . trim ( )
14+ }
Original file line number Diff line number Diff line change 106106<script >
107107import { clipboardWriteText } from ' @common/utils/electron'
108108import { assertApiSupport } from ' @renderer/store/utils'
109+ import { shouldCopyListTextOnContextMenu , formatListSelectionText } from ' @renderer/utils/listContextMenu.mjs'
109110import SearchList from ' ./components/SearchList.vue'
110111import MusicSortModal from ' ./components/MusicSortModal.vue'
111112import MusicToggleModal from ' ./components/MusicToggleModal.vue'
@@ -268,14 +269,17 @@ export default {
268269 menuClick (action, index)
269270 }
270271 const handleListRightClick = (event ) => {
271- if (! event .target .classList .contains (' select' )) return
272+ const selectionText = window .getSelection ().toString ()
273+ if (! shouldCopyListTextOnContextMenu ({
274+ isSelectTextTarget: event .target .classList .contains (' select' ),
275+ selectionText,
276+ })) return
272277 event .stopImmediatePropagation ()
273278 let classList = dom_listContent .value .classList
274279 classList .add (' copying' )
275280 window .requestAnimationFrame (() => {
276- let str = window .getSelection ().toString ()
277281 classList .remove (' copying' )
278- str = str . split ( / \n\n / ). map ( s => s . replace ( / \n / g , ' ' )). join ( ' \n ' ). trim ( )
282+ let str = formatListSelectionText ( window . getSelection (). toString () )
279283 if (! str .length ) return
280284 clipboardWriteText (str)
281285 })
You can’t perform that action at this time.
0 commit comments