當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript TextEdit.delete方法代碼示例

本文整理匯總了TypeScript中vscode.TextEdit.delete方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript TextEdit.delete方法的具體用法?TypeScript TextEdit.delete怎麽用?TypeScript TextEdit.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vscode.TextEdit的用法示例。


在下文中一共展示了TextEdit.delete方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: provideEdits

    provideEdits(document: TextDocument, position: Position, ch: string, options: FormattingOptions, line: TextLine): TextEdit[] {
        // We can have else for the following blocks:
        // if:
        // elif x:
        // for x in y:
        // while x:

        // We need to find a block statement that is less than or equal to this statement block (but not greater)
        for (let lineNumber = position.line - 1; lineNumber >= 0; lineNumber--) {
            const prevLine = document.lineAt(lineNumber);
            const prevLineText = prevLine.text;

            // Oops, we've reached a boundary (like the function or class definition)
            // Get out of here
            if (this.boundaryRegExps.some(value => value.test(prevLineText))) {
                return [];
            }

            const blockRegEx = this.previousBlockRegExps.find(value => value.test(prevLineText));
            if (!blockRegEx) {
                continue;
            }

            const startOfBlockInLine = prevLine.firstNonWhitespaceCharacterIndex;
            if (startOfBlockInLine > line.firstNonWhitespaceCharacterIndex) {
                continue;
            }

            const startPosition = new Position(position.line, 0);
            const endPosition = new Position(position.line, line.firstNonWhitespaceCharacterIndex - startOfBlockInLine);

            if (startPosition.isEqual(endPosition)) {
                // current block cannot be at the same level as a preivous block
                continue;
            }
            if (options.insertSpaces) {
                return [
                    TextEdit.delete(new Range(startPosition, endPosition))
                ];
            }
            else {
                // Delete everything before the block and insert the same characters we have in the previous block
                const prefixOfPreviousBlock = prevLineText.substring(0, startOfBlockInLine);

                const startDeletePosition = new Position(position.line, 0);
                const endDeletePosition = new Position(position.line, line.firstNonWhitespaceCharacterIndex);

                return [
                    TextEdit.delete(new Range(startDeletePosition, endDeletePosition)),
                    TextEdit.insert(startDeletePosition, prefixOfPreviousBlock)
                ];
            }
        }

        return [];
    }
開發者ID:walkoncross,項目名稱:pythonVSCode,代碼行數:56,代碼來源:codeBlockFormatProvider.ts

示例2: getEditsForDeletingTralingSpaces

 /**
  * Returns the edits required to delete the trailings spaces from a document
  *
  * @param {vscode.TextDocument} document The document in which the trailing spaces should be found
  * @returns {vscode.TextEdit[]} An array of edits required to delete the trailings spaces from the document
  */
 public getEditsForDeletingTralingSpaces(document: vscode.TextDocument): vscode.TextEdit[] {
     let ranges: vscode.Range[] = this.getRangesToDelete(document);
     let edits: vscode.TextEdit[] = new Array<vscode.TextEdit>(ranges.length);
     for (let i: number = ranges.length - 1; i >= 0; i--) {
         edits[ranges.length - 1 - i] = vscode.TextEdit.delete(ranges[i]);
     }
     this.showStatusBarMessage(document, ranges.length);
     return edits;
 }
開發者ID:shardulm94,項目名稱:vscode-trailingspaces,代碼行數:15,代碼來源:trailing-spaces.ts

示例3: apply

	apply(): TextEdit {
		switch (this.action) {
			case EditTypes.EDIT_INSERT:
				return TextEdit.insert(this.start, this.text);
			case EditTypes.EDIT_DELETE:
				return TextEdit.delete(new Range(this.start, this.end));
			case EditTypes.EDIT_REPLACE:
				return TextEdit.replace(new Range(this.start, this.end), this.text);
		}
	}
開發者ID:oliverkofoed,項目名稱:vscode-go,代碼行數:10,代碼來源:util.ts

示例4:

					return this.sessionStore.activityTypes.map(activity => {
						const item = new vsc.CompletionItem(activity, vsc.CompletionItemKind.TypeParameter);
						item.insertText = `${activity}:`;

						if (word.endsWith(':')) {
							const currentLine = document.lineAt(position.line);

							item.additionalTextEdits = [
								vsc.TextEdit.delete(new vsc.Range(position, position.with(undefined, currentLine.text.length)))
							];
						}

						return item;
					});
開發者ID:ipatalas,項目名稱:vscode-sprint-planner,代碼行數:14,代碼來源:activityCompletionProvider.ts

示例5: trimLineTrailingWhitespace

function trimLineTrailingWhitespace(line: TextLine) {
	const trimmedLine = trimTrailingWhitespace(line.text);

	if (trimmedLine === line.text) {
		return;
	}

	const whitespaceBegin = new Position(
		line.lineNumber,
		trimmedLine.length
	);
	const whitespaceEnd = new Position(
		line.lineNumber,
		line.text.length
	);
	const whitespace = new Range(
		whitespaceBegin,
		whitespaceEnd
	);

	return TextEdit.delete(whitespace);
}
開發者ID:rlugojr,項目名稱:editorconfig-vscode,代碼行數:22,代碼來源:trimTrailingWhitespace.ts

示例6: suite

suite('Else blocks with indentation of Tab', () => {
    suiteSetup(async () => {
        await initialize();
        fs.ensureDirSync(path.dirname(outPythoFilesPath));

        ['elseBlocksTab.py'].forEach(file => {
            const targetFile = path.join(outPythoFilesPath, file);
            if (fs.existsSync(targetFile)) { fs.unlinkSync(targetFile); }
            fs.copySync(path.join(srcPythoFilesPath, file), targetFile);
        });
    });
    suiteTeardown(() => closeActiveWindows());
    teardown(() => closeActiveWindows());

    interface TestCase {
        title: string;
        line: number;
        column: number;
        expectedEdits: vscode.TextEdit[];
    }
    const testCases: TestCase[] = [
        {
            title: 'elif off by tab',
            line: 4, column: 18,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(4, 0, 4, 1))
            ]
        },
        {
            title: 'elif off by tab',
            line: 7, column: 18,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(7, 0, 7, 1))
            ]
        },
        {
            title: 'elif off by tab again',
            line: 21, column: 18,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(21, 0, 21, 1))
            ]
        },
        {
            title: 'else off by tab',
            line: 38, column: 7,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(38, 0, 38, 1))
            ]
        },
        {
            title: 'else: off by tab inside a for loop',
            line: 47, column: 13,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(47, 0, 47, 1))
            ]
        },
        {
            title: 'else: off by tab inside a try',
            line: 57, column: 9,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(57, 0, 57, 1))
            ]
        },
        {
            title: 'elif off by a tab inside a function',
            line: 66, column: 20,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(66, 0, 66, 1))
            ]
        },
        {
            title: 'elif off by a tab inside a function should not format',
            line: 69, column: 20,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(69, 0, 69, 1))
            ]
        },
        {
            title: 'elif off by a tab inside a function',
            line: 83, column: 20,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(83, 0, 83, 1))
            ]
        },
        {
            title: 'else: off by tab inside if of a for and for in a function',
            line: 109, column: 15,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(109, 0, 109, 1))
            ]
        },
        {
            title: 'else: off by tab inside try in a function',
            line: 119, column: 11,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(119, 0, 119, 1))
            ]
        },
        {
            title: 'else: off by tab inside while in a function',
//.........這裏部分代碼省略.........
開發者ID:,項目名稱:,代碼行數:101,代碼來源:

示例7: suite

suite('Try blocks with indentation of 4 spaces', () => {
    suiteSetup(done => {
        initialize().then(() => {
            pythonSettings.pythonPath = PYTHON_PATH;
            fs.ensureDirSync(path.dirname(outPythoFilesPath));

            ['tryBlocks4.py'].forEach(file => {
                const targetFile = path.join(outPythoFilesPath, file);
                if (fs.existsSync(targetFile)) { fs.unlinkSync(targetFile); }
                fs.copySync(path.join(srcPythoFilesPath, file), targetFile);
            });
        }).then(done).catch(done);
    });
    suiteTeardown(done => {
        closeActiveWindows().then(done, done);
    });
    teardown(done => {
        closeActiveWindows().then(done, done);
    });

    interface TestCase {
        title: string;
        line: number;
        column: number;
        expectedEdits: vscode.TextEdit[];
    }
    const testCases: TestCase[] = [
        {
            title: 'except off by tab',
            line: 6, column: 22,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(6, 0, 6, 4))
            ]
        },
        {
            title: 'except off by one should not be formatted',
            line: 15, column: 21,
            expectedEdits: []
        },
        {
            title: 'except off by tab inside a for loop',
            line: 35, column: 13,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(35, 0, 35, 4))
            ]
        },
        {
            title: 'except off by one inside a for loop should not be formatted',
            line: 47, column: 12,
            expectedEdits: [
            ]
        },
        {
            title: 'except IOError: off by tab inside a for loop',
            line: 54, column: 19,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(54, 0, 54, 4))
            ]
        },
        {
            title: 'else: off by tab inside a for loop',
            line: 76, column: 9,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(76, 0, 76, 4))
            ]
        },
        {
            title: 'except ValueError:: off by tab inside a function',
            line: 143, column: 22,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(143, 0, 143, 4))
            ]
        },
        {
            title: 'except ValueError as err: off by one inside a function should not be formatted',
            line: 157, column: 25,
            expectedEdits: [
            ]
        },
        {
            title: 'else: off by tab inside function',
            line: 172, column: 11,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(172, 0, 172, 4))
            ]
        },
        {
            title: 'finally: off by tab inside function',
            line: 195, column: 12,
            expectedEdits: [
                vscode.TextEdit.delete(new vscode.Range(195, 0, 195, 4))
            ]
        }
    ];

    const formatOptions: vscode.FormattingOptions = {
        insertSpaces: true, tabSize: 4
    };

    testCases.forEach((testCase, index) => {
//.........這裏部分代碼省略.........
開發者ID:walkoncross,項目名稱:pythonVSCode,代碼行數:101,代碼來源:extension.onTypeFormat.test.ts


注:本文中的vscode.TextEdit.delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。