MCPcopy Create free account
hub / github.com/massCodeIO/massCode / selectSnippet

Function selectSnippet

src/renderer/composables/useSnippets.ts:663–695  ·  view source on GitHub ↗
(snippetId: number, withShift = false)

Source from the content-addressed store, hash-verified

661}
662
663function selectSnippet(snippetId: number, withShift = false) {
664 if (!withShift) {
665 selectedSnippetIds.value = [snippetId]
666 state.snippetId = snippetId
667 state.snippetContentIndex = 0
668 return
669 }
670
671 if (state.snippetId !== undefined) {
672 const source = isSearch.value ? snippetsBySearch.value : snippets.value
673
674 if (source?.length) {
675 const orderedIds = source.map(snippet => snippet.id)
676 const rangeSelection = getContiguousSelection(
677 orderedIds,
678 state.snippetId,
679 snippetId,
680 )
681
682 if (rangeSelection.length) {
683 selectedSnippetIds.value = rangeSelection
684 lastSelectedSnippetId.value = snippetId
685 state.snippetContentIndex = 0
686 }
687 }
688 }
689 else {
690 selectedSnippetIds.value = [snippetId]
691 lastSelectedSnippetId.value = snippetId
692 state.snippetId = snippetId
693 state.snippetContentIndex = 0
694 }
695}
696
697function selectFirstSnippet() {
698 let firstSnippet: SnippetsResponse[0] | undefined

Callers 3

createSnippetAndSelectFunction · 0.85
selectSearchSnippetFunction · 0.85
openSnippetDeepLinkFunction · 0.85

Calls 1

getContiguousSelectionFunction · 0.90

Tested by

no test coverage detected