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


TypeScript TextEditor.edit方法代碼示例

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


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

示例1: runNormalMode

	public runNormalMode(ctrl: IController, ed:TextEditor, repeatCount: number, args: string): boolean {
		let register = ctrl.getDeleteRegister();
		if (!register) {
			// No delete register - beep!!
			return true;
		}

		let str = repeatString(register.content, repeatCount);

		let pos = this.pos(ed);
		if (!register.isWholeLine) {
			ed.edit((builder) => {
				builder.insert(new Position(pos.line, pos.character + 1), str);
			});
			return true;
		}

		let doc = this.doc(ed);
		let insertLine = pos.line + 1;
		let insertCharacter = 0;

		if (insertLine >=  doc.lineCount) {
			// on last line
			insertLine = doc.lineCount - 1;
			insertCharacter = doc.lineAt(insertLine).text.length;
			str = '\n' + str;
		}

		ed.edit((builder) => {
			builder.insert(new Position(insertLine, insertCharacter), str);
		});

		return true;
	}
開發者ID:DanEEStar,項目名稱:vscode-vim,代碼行數:34,代碼來源:operators.ts

示例2: applypatches

/**
 * Applies the given set of patches to the document in the given editor
 *
 * @param patches array of patches to be applied
 * @param editor the TextEditor whose document will be updated
 */
function applypatches(patches: dmp.Patch[], editor: TextEditor): Thenable<boolean> {
	let totalEdits: Edit[] = [];
	patches.reverse().forEach((patch: dmp.Patch) => {
		// Godoctor provides a diff for each line, but the text accompanying the diff does not end with '\n'
		// GetEditsFromDiffs(..) expects the '\n' to exist in the text wherever there is a new line.
		// So add one for each diff from getdoctor
		for (let i = 0; i < patch.diffs.length; i++) {
			patch.diffs[i][1] += '\n';
		}
		let edits = GetEditsFromDiffs(patch.diffs, patch.start1);
		totalEdits = totalEdits.concat(edits);
	});

	return editor.edit((editBuilder) => {
		totalEdits.forEach((edit) => {
			switch (edit.action) {
				case EditTypes.EDIT_INSERT:
					editBuilder.insert(edit.start, edit.text);
					break;
				case EditTypes.EDIT_DELETE:
					editBuilder.delete(new Range(edit.start, edit.end));
					break;
				case EditTypes.EDIT_REPLACE:
					editBuilder.replace(new Range(edit.start, edit.end), edit.text);
					break;
			}
		});
	});
}
開發者ID:oliverkofoed,項目名稱:vscode-go,代碼行數:35,代碼來源:goExtractMethod.ts

示例3: px2em

export default async function px2em(textEditor: TextEditor, lastValue: string | undefined) {
  const doc = textEditor.document;
  const selections = getValidSelections(textEditor, doc);

  if (selections.length === 0) { return; }

  textEditor.selections = selections;

  let option: InputBoxOptions = {
    placeHolder: '請輸入font-size的基準值',
    prompt: '單位為px或rem,當單位為px時,可省略px。',
    value: lastValue,
  };

  let input = await window.showInputBox(option);
  if (hasInvalidInput(input)) { return; }

  let match = input.match(regex) as RegExpMatchArray;
  let factor = +match[1];
  let unit = match[2];

  if (!unit) { unit = 'px'; }
  lastValue = factor + unit;

  if (unit === 'rem') { factor *= config.htmlFontSize; }

  textEditor.edit((edit) => {
    convert(textEditor, edit, factor, 'em');
  });

  return lastValue;
}
開發者ID:Maroon1,項目名稱:px2rem,代碼行數:32,代碼來源:px2em.ts

示例4: runVisualMode

	public runVisualMode(ctrl: IController, ed:TextEditor, args: string): boolean {
		if (args.length === 0) {
			// input not ready
			return false;
		}

		let doc = this.doc(ed);
		let sel = this.sel(ed);

		let srcString = doc.getText(sel);
		let dstString = '';
		for (let i = 0; i < srcString.length; i++) {
			let ch = srcString.charAt(i);
			if (ch === '\r' || ch === '\n') {
				dstString += ch;
			} else {
				dstString += args;
			}
		}

		ed.edit((builder) => {
			builder.replace(sel, dstString);
		});

		return true;
	}
開發者ID:DanEEStar,項目名稱:vscode-vim,代碼行數:26,代碼來源:operators.ts

示例5: updateCSSNode

function updateCSSNode(editor: TextEditor, property: Property): Thenable<boolean> {
	const rule: Rule = property.parent;
	let currentPrefix = '';

	// Find vendor prefix of given property node
	for (let i = 0; i < vendorPrefixes.length; i++) {
		if (property.name.startsWith(vendorPrefixes[i])) {
			currentPrefix = vendorPrefixes[i];
			break;
		}
	}

	const propertyName = property.name.substr(currentPrefix.length);
	const propertyValue = property.value;

	return editor.edit(builder => {
		// Find properties with vendor prefixes, update each
		vendorPrefixes.forEach(prefix => {
			if (prefix === currentPrefix) {
				return;
			}
			let vendorProperty = getCssPropertyFromRule(rule, prefix + propertyName);
			if (vendorProperty) {
				builder.replace(new Range(vendorProperty.valueToken.start, vendorProperty.valueToken.end), propertyValue);
			}
		});
	});
}
開發者ID:Chan-PH,項目名稱:vscode,代碼行數:28,代碼來源:reflectCssValue.ts

示例6: function

 const setText = async function (editor: TextEditor, text: string) {
     return editor.edit((editBuilder: TextEditorEdit) => {
         const doc = editor.document;
         const startPos = new Position(0, 0);
         const lastLine = doc.lineAt(doc.lineCount - 1);
         const endPos = lastLine.range.end;
         const entireRange = new Range(startPos, endPos);
         editBuilder.replace(entireRange, text);
         editBuilder.setEndOfLine(EndOfLine.LF);
     });
 };
開發者ID:sgryjp,項目名稱:japanese-word-handler,代碼行數:11,代碼來源:extension.test.ts

示例7: parinfer

	function parinfer(editor: TextEditor, position: Position = null) {
		const document = editor.document;
		const uri = document.uri.toString();
		const input = document.getText();
		const fn = (getMode(uri) === Mode.Indent && position) ? indentMode : parenMode;
		const output = position ? fn(input, fromEditorPosition(position)) : fn(input);

		if (typeof output !== 'string') {
			return;
		}

		const range = new Range(new Position(0, 0), document.positionAt(input.length));
		editor.edit(builder => builder.replace(range, output));
	}
開發者ID:brandonbloom,項目名稱:vscode-parinfer,代碼行數:14,代碼來源:extension.ts

示例8: replacePrevChar

	public replacePrevChar(editor: TextEditor, text: string, replaceCharCnt: number): boolean {
		if (this._currentMode !== Mode.NORMAL && this._currentMode !== Mode.REPLACE) {
			return false;
		}
		if (this._currentMode === Mode.REPLACE) {
			let pos = editor.selection.active;
			editor.edit((builder) => {
				builder.replace(new Range(pos.line, pos.character - replaceCharCnt, pos.line, pos.character), text);
			});

			return true;
		}
		// Not supporting IME building in NORMAL mode
		return true;
	}
開發者ID:DanEEStar,項目名稱:vscode-vim,代碼行數:15,代碼來源:controller.ts

示例9: prepForDocCompletion

	/**
	 * Prepare the area around the position for insertion of the jsdoc.
	 *
	 * Removes any the prefix and suffix of a possible jsdoc
	 */
	private prepForDocCompletion(editor: TextEditor, position: Position): Thenable<Position> {
		const line = editor.document.lineAt(position.line).text;
		const prefix = line.slice(0, position.character).match(/\/\**\s*$/);
		const suffix = line.slice(position.character).match(/^\s*\**\//);
		if (!prefix && !suffix) {
			// Nothing to remove
			return Promise.resolve(position);
		}

		const start = position.translate(0, prefix ? -prefix[0].length : 0);
		return editor.edit(
			edits => {
				edits.delete(new Range(start, position.translate(0, suffix ? suffix[0].length : 0)));
			}, {
				undoStopBefore: true,
				undoStopAfter: false
			}).then(() => start);
	}
開發者ID:yuit,項目名稱:vscode,代碼行數:23,代碼來源:jsDocCompletionProvider.ts


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