当前位置: 首页>>代码示例>>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;未经允许,请勿转载。