mirror of
https://github.com/voideditor/void
synced 2026-05-23 17:38:23 +00:00
Merge pull request #858 from chrisnumbers/main
Updated code selection to properly parse selected lines
This commit is contained in:
commit
5aaa1604e1
1 changed files with 17 additions and 4 deletions
|
|
@ -575,11 +575,24 @@ export const messageOfSelection = async (
|
|||
) => {
|
||||
const lineNumAddition = (range: [number, number]) => ` (lines ${range[0]}:${range[1]})`
|
||||
|
||||
if (s.type === 'File' || s.type === 'CodeSelection') {
|
||||
if (s.type === 'CodeSelection') {
|
||||
const { val } = await readFile(opts.fileService, s.uri, DEFAULT_FILE_SIZE_LIMIT)
|
||||
const lineNumAdd = s.type === 'CodeSelection' ? lineNumAddition(s.range) : ''
|
||||
const content = val === null ? 'null' : `${tripleTick[0]}${s.language}\n${val}\n${tripleTick[1]}`
|
||||
const str = `${s.uri.fsPath}${lineNumAdd}:\n${content}`
|
||||
const lines = val?.split('\n')
|
||||
|
||||
const innerVal = lines?.slice(s.range[0] - 1, s.range[1]).join('\n')
|
||||
const content = !lines ? ''
|
||||
: `${tripleTick[0]}${s.language}\n${innerVal}\n${tripleTick[1]}`
|
||||
const str = `${s.uri.fsPath}${lineNumAddition(s.range)}:\n${content}`
|
||||
return str
|
||||
}
|
||||
else if (s.type === 'File') {
|
||||
const { val } = await readFile(opts.fileService, s.uri, DEFAULT_FILE_SIZE_LIMIT)
|
||||
|
||||
const innerVal = val
|
||||
const content = val === null ? ''
|
||||
: `${tripleTick[0]}${s.language}\n${innerVal}\n${tripleTick[1]}`
|
||||
|
||||
const str = `${s.uri.fsPath}:\n${content}`
|
||||
return str
|
||||
}
|
||||
else if (s.type === 'Folder') {
|
||||
|
|
|
|||
Loading…
Reference in a new issue