mirror of
https://github.com/any86/any-rule.git
synced 2025-07-14 15:38:58 +08:00
fix: 修正replace范围错误
This commit is contained in:
parent
8b38ec1521
commit
d7569e208a
@ -12,23 +12,23 @@ export default function (context: ExtensionContext, RULES: Rule[]) {
|
|||||||
if (!linePrefix.endsWith(COMPLETION_TRIGGER_ID)) return;
|
if (!linePrefix.endsWith(COMPLETION_TRIGGER_ID)) return;
|
||||||
|
|
||||||
// showQuickPick
|
// showQuickPick
|
||||||
let index = -1;
|
window.showQuickPick(RULES.map(({ examples, title, rule }, i) => {
|
||||||
window.showQuickPick(RULES.map(({ examples, title }, i) => {
|
// const match = title.match(/\((.+)\)/);
|
||||||
index = i;
|
return {
|
||||||
return {
|
|
||||||
label: title,
|
label: title,
|
||||||
// description:'例如: ' + examples[0],
|
// description: null !== match ? match[1] : '',
|
||||||
detail:`例如: ${examples.join(' 或 ')}`
|
rule: String(rule), // 非标准字段, 仅仅为了传值
|
||||||
|
detail: `例如: ${examples.join(' 或 ')}`
|
||||||
};
|
};
|
||||||
}), {
|
}), {
|
||||||
placeHolder: '请输入关键词',
|
placeHolder: '请输入关键词',
|
||||||
// onDidSelectItem(item){
|
// onDidSelectItem(item){
|
||||||
// console.log(item)
|
// console.log(item)
|
||||||
// }
|
// }
|
||||||
}).then(text => {
|
}).then(item => {
|
||||||
if (!text) return
|
if (!item) return
|
||||||
insertRule(document, position, '' + RULES[index].rule)
|
insertRule(document, position, item.rule)
|
||||||
window.showInformationMessage('' + RULES[index].rule);
|
window.showInformationMessage(item.rule);
|
||||||
});
|
});
|
||||||
|
|
||||||
return void 0;
|
return void 0;
|
||||||
@ -50,18 +50,20 @@ function insertRule(document: TextDocument, position: Position, ruleString: stri
|
|||||||
// 起始
|
// 起始
|
||||||
const startPostion = new Position(line.lineNumber, line.text.indexOf(COMPLETION_TRIGGER_ID));
|
const startPostion = new Position(line.lineNumber, line.text.indexOf(COMPLETION_TRIGGER_ID));
|
||||||
|
|
||||||
// 结束
|
// 结束(replace用)
|
||||||
const endPostion = new Position(line.lineNumber, startPostion.character + ruleString.length + COMPLETION_TRIGGER_ID.length);
|
const endPostion = new Position(line.lineNumber, startPostion.character + COMPLETION_TRIGGER_ID.length);
|
||||||
window.showInformationMessage('asdad')
|
|
||||||
|
|
||||||
// window.showInformationMessage(
|
// window.showInformationMessage(
|
||||||
// '' + startPostion.character
|
// '' + startPostion.character
|
||||||
// , ''+endPostion.character
|
// , '' + endPostion.character
|
||||||
// );
|
// );
|
||||||
|
|
||||||
editBuilder.replace(new Range(startPostion, endPostion), ruleString);
|
editBuilder.replace(new Range(startPostion, endPostion), ruleString);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
// 结束(selection用)
|
||||||
|
const endPostion = new Position(line.lineNumber, startPostion.character + ruleString.length);
|
||||||
editor.selection = new Selection(startPostion, endPostion);
|
editor.selection = new Selection(startPostion, endPostion);
|
||||||
}, 0);
|
}, 0);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user