mirror of
https://github.com/godotengine/godot-vscode-plugin.git
synced 2025-12-31 13:48:24 +03:00
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import {TextDocument, Position} from 'vscode';
|
|
|
|
export function isStr(content:string) {
|
|
return (content.startsWith("'") || content.startsWith('"') || content.startsWith('@"') ) && (content.endsWith("'") || content.endsWith('"'));
|
|
}
|
|
|
|
export function getSelectedContent(document: TextDocument, position: Position):string {
|
|
const line = document.lineAt(position);
|
|
const wordRange = document.getWordRangeAtPosition(position) ;
|
|
const machs = line.text.match(/[A-z_]+[A-z_0-9]*|".*?"|'.*?'|@".*?"/g)
|
|
let res = line.text.substring(wordRange.start.character, wordRange.end.character);
|
|
machs.map(m=>{
|
|
if(m) {
|
|
const startPos = line.text.indexOf(m);
|
|
const endPos = startPos + m.length;
|
|
if(isStr(m) && startPos != -1 && wordRange.start.character >= startPos && wordRange.end.character <= endPos){
|
|
res = m;
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
return res;
|
|
};
|
|
|
|
export function getStrContent(rawstr: string):string {
|
|
let ss = rawstr;
|
|
if(isStr(ss)) {
|
|
ss = ss.replace(/"|'|@"|"""/g,"")
|
|
}
|
|
return ss;
|
|
} |