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


TypeScript BlockCommentCommand._haystackHasNeedleAtOffset方法代碼示例

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


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

示例1: _analyzeLines

	/**
	 * Analyze lines and decide which lines are relevant and what the toggle should do.
	 * Also, build up several offsets and lengths useful in the generation of editor operations.
	 */
	public static _analyzeLines(type: Type, model: ISimpleModel, lines: ILinePreflightData[], startLineNumber: number): IPreflightData {
		let onlyWhitespaceLines = true;

		let shouldRemoveComments: boolean;
		if (type === Type.Toggle) {
			shouldRemoveComments = true;
		} else if (type === Type.ForceAdd) {
			shouldRemoveComments = false;
		} else {
			shouldRemoveComments = true;
		}

		for (let i = 0, lineCount = lines.length; i < lineCount; i++) {
			const lineData = lines[i];
			const lineNumber = startLineNumber + i;

			const lineContent = model.getLineContent(lineNumber);
			const lineContentStartOffset = strings.firstNonWhitespaceIndex(lineContent);

			if (lineContentStartOffset === -1) {
				// Empty or whitespace only line
				if (type === Type.Toggle) {
					lineData.ignore = true;
				} else if (type === Type.ForceAdd) {
					lineData.ignore = true;
				} else {
					lineData.ignore = true;
				}
				lineData.commentStrOffset = lineContent.length;
				continue;
			}

			onlyWhitespaceLines = false;
			lineData.ignore = false;
			lineData.commentStrOffset = lineContentStartOffset;

			if (shouldRemoveComments && !BlockCommentCommand._haystackHasNeedleAtOffset(lineContent, lineData.commentStr, lineContentStartOffset)) {
				if (type === Type.Toggle) {
					// Every line so far has been a line comment, but this one is not
					shouldRemoveComments = false;
				} else if (type === Type.ForceAdd) {
					// Will not happen
				} else {
					lineData.ignore = true;
				}
			}

			if (shouldRemoveComments) {
				const commentStrEndOffset = lineContentStartOffset + lineData.commentStrLength;
				if (commentStrEndOffset < lineContent.length && lineContent.charCodeAt(commentStrEndOffset) === CharCode.Space) {
					lineData.commentStrLength += 1;
				}
			}
		}

		if (type === Type.Toggle && onlyWhitespaceLines) {
			// For only whitespace lines, we insert comments
			shouldRemoveComments = false;

			// Also, no longer ignore them
			for (let i = 0, lineCount = lines.length; i < lineCount; i++) {
				lines[i].ignore = false;
			}
		}

		return {
			supported: true,
			shouldRemoveComments: shouldRemoveComments,
			lines: lines
		};
	}
開發者ID:VishalMadhvani,項目名稱:vscode,代碼行數:75,代碼來源:lineCommentCommand.ts


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