Best JavaScript code snippet using wpt
cursorMoveOperations.ts
Source:cursorMoveOperations.ts
1/*---------------------------------------------------------------------------------------------2 * Copyright (c) Microsoft Corporation. All rights reserved.3 * Licensed under the MIT License. See License.txt in the project root for license information.4 *--------------------------------------------------------------------------------------------*/5'use strict';6import { SingleCursorState, CursorColumns, CursorConfiguration, ICursorSimpleModel } from 'vs/editor/common/controller/cursorCommon';7import { Position } from 'vs/editor/common/core/position';8import { Range } from 'vs/editor/common/core/range';9export class CursorPosition {10 _cursorPositionBrand: void;11 public readonly lineNumber: number;12 public readonly column: number;13 public readonly leftoverVisibleColumns: number;14 constructor(lineNumber: number, column: number, leftoverVisibleColumns: number) {15 this.lineNumber = lineNumber;16 this.column = column;17 this.leftoverVisibleColumns = leftoverVisibleColumns;18 }19}20export class MoveOperations {21 public static left(config: CursorConfiguration, model: ICursorSimpleModel, lineNumber: number, column: number): CursorPosition {22 if (column > model.getLineMinColumn(lineNumber)) {23 if (CursorColumns.isLowSurrogate(model, lineNumber, column - 2)) {24 // character before column is a low surrogate25 column = column - 2;26 } else {27 column = column - 1;28 }29 } else if (lineNumber > 1) {30 lineNumber = lineNumber - 1;31 column = model.getLineMaxColumn(lineNumber);32 }33 return new CursorPosition(lineNumber, column, 0);34 }35 public static moveLeft(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean, noOfColumns: number): SingleCursorState {36 let lineNumber: number,37 column: number;38 if (cursor.hasSelection() && !inSelectionMode) {39 // If we are in selection mode, move left without selection cancels selection and puts cursor at the beginning of the selection40 lineNumber = cursor.selection.startLineNumber;41 column = cursor.selection.startColumn;42 } else {43 let r = MoveOperations.left(config, model, cursor.position.lineNumber, cursor.position.column - (noOfColumns - 1));44 lineNumber = r.lineNumber;45 column = r.column;46 }47 return cursor.move(inSelectionMode, lineNumber, column, 0);48 }49 public static right(config: CursorConfiguration, model: ICursorSimpleModel, lineNumber: number, column: number): CursorPosition {50 if (column < model.getLineMaxColumn(lineNumber)) {51 if (CursorColumns.isHighSurrogate(model, lineNumber, column - 1)) {52 // character after column is a high surrogate53 column = column + 2;54 } else {55 column = column + 1;56 }57 } else if (lineNumber < model.getLineCount()) {58 lineNumber = lineNumber + 1;59 column = model.getLineMinColumn(lineNumber);60 }61 return new CursorPosition(lineNumber, column, 0);62 }63 public static moveRight(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean, noOfColumns: number): SingleCursorState {64 let lineNumber: number,65 column: number;66 if (cursor.hasSelection() && !inSelectionMode) {67 // If we are in selection mode, move right without selection cancels selection and puts cursor at the end of the selection68 lineNumber = cursor.selection.endLineNumber;69 column = cursor.selection.endColumn;70 } else {71 let r = MoveOperations.right(config, model, cursor.position.lineNumber, cursor.position.column + (noOfColumns - 1));72 lineNumber = r.lineNumber;73 column = r.column;74 }75 return cursor.move(inSelectionMode, lineNumber, column, 0);76 }77 public static down(config: CursorConfiguration, model: ICursorSimpleModel, lineNumber: number, column: number, leftoverVisibleColumns: number, count: number, allowMoveOnLastLine: boolean): CursorPosition {78 const currentVisibleColumn = CursorColumns.visibleColumnFromColumn(model.getLineContent(lineNumber), column, config.tabSize) + leftoverVisibleColumns;79 lineNumber = lineNumber + count;80 let lineCount = model.getLineCount();81 if (lineNumber > lineCount) {82 lineNumber = lineCount;83 if (allowMoveOnLastLine) {84 column = model.getLineMaxColumn(lineNumber);85 } else {86 column = Math.min(model.getLineMaxColumn(lineNumber), column);87 if (CursorColumns.isInsideSurrogatePair(model, lineNumber, column)) {88 column = column - 1;89 }90 }91 } else {92 column = CursorColumns.columnFromVisibleColumn2(config, model, lineNumber, currentVisibleColumn);93 if (CursorColumns.isInsideSurrogatePair(model, lineNumber, column)) {94 column = column - 1;95 }96 }97 leftoverVisibleColumns = currentVisibleColumn - CursorColumns.visibleColumnFromColumn(model.getLineContent(lineNumber), column, config.tabSize);98 return new CursorPosition(lineNumber, column, leftoverVisibleColumns);99 }100 public static moveDown(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean, linesCount: number): SingleCursorState {101 let lineNumber: number,102 column: number;103 if (cursor.hasSelection() && !inSelectionMode) {104 // If we are in selection mode, move down acts relative to the end of selection105 lineNumber = cursor.selection.endLineNumber;106 column = cursor.selection.endColumn;107 } else {108 lineNumber = cursor.position.lineNumber;109 column = cursor.position.column;110 }111 let r = MoveOperations.down(config, model, lineNumber, column, cursor.leftoverVisibleColumns, linesCount, true);112 return cursor.move(inSelectionMode, r.lineNumber, r.column, r.leftoverVisibleColumns);113 }114 public static translateDown(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState): SingleCursorState {115 let selection = cursor.selection;116 let selectionStart = MoveOperations.down(config, model, selection.selectionStartLineNumber, selection.selectionStartColumn, cursor.selectionStartLeftoverVisibleColumns, 1, false);117 let position = MoveOperations.down(config, model, selection.positionLineNumber, selection.positionColumn, cursor.leftoverVisibleColumns, 1, false);118 return new SingleCursorState(119 new Range(selectionStart.lineNumber, selectionStart.column, selectionStart.lineNumber, selectionStart.column),120 selectionStart.leftoverVisibleColumns,121 new Position(position.lineNumber, position.column),122 position.leftoverVisibleColumns123 );124 }125 public static up(config: CursorConfiguration, model: ICursorSimpleModel, lineNumber: number, column: number, leftoverVisibleColumns: number, count: number, allowMoveOnFirstLine: boolean): CursorPosition {126 const currentVisibleColumn = CursorColumns.visibleColumnFromColumn(model.getLineContent(lineNumber), column, config.tabSize) + leftoverVisibleColumns;127 lineNumber = lineNumber - count;128 if (lineNumber < 1) {129 lineNumber = 1;130 if (allowMoveOnFirstLine) {131 column = model.getLineMinColumn(lineNumber);132 } else {133 column = Math.min(model.getLineMaxColumn(lineNumber), column);134 if (CursorColumns.isInsideSurrogatePair(model, lineNumber, column)) {135 column = column - 1;136 }137 }138 } else {139 column = CursorColumns.columnFromVisibleColumn2(config, model, lineNumber, currentVisibleColumn);140 if (CursorColumns.isInsideSurrogatePair(model, lineNumber, column)) {141 column = column - 1;142 }143 }144 leftoverVisibleColumns = currentVisibleColumn - CursorColumns.visibleColumnFromColumn(model.getLineContent(lineNumber), column, config.tabSize);145 return new CursorPosition(lineNumber, column, leftoverVisibleColumns);146 }147 public static moveUp(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean, linesCount: number): SingleCursorState {148 let lineNumber: number,149 column: number;150 if (cursor.hasSelection() && !inSelectionMode) {151 // If we are in selection mode, move up acts relative to the beginning of selection152 lineNumber = cursor.selection.startLineNumber;153 column = cursor.selection.startColumn;154 } else {155 lineNumber = cursor.position.lineNumber;156 column = cursor.position.column;157 }158 let r = MoveOperations.up(config, model, lineNumber, column, cursor.leftoverVisibleColumns, linesCount, true);159 return cursor.move(inSelectionMode, r.lineNumber, r.column, r.leftoverVisibleColumns);160 }161 public static translateUp(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState): SingleCursorState {162 let selection = cursor.selection;163 let selectionStart = MoveOperations.up(config, model, selection.selectionStartLineNumber, selection.selectionStartColumn, cursor.selectionStartLeftoverVisibleColumns, 1, false);164 let position = MoveOperations.up(config, model, selection.positionLineNumber, selection.positionColumn, cursor.leftoverVisibleColumns, 1, false);165 return new SingleCursorState(166 new Range(selectionStart.lineNumber, selectionStart.column, selectionStart.lineNumber, selectionStart.column),167 selectionStart.leftoverVisibleColumns,168 new Position(position.lineNumber, position.column),169 position.leftoverVisibleColumns170 );171 }172 public static moveToBeginningOfLine(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean): SingleCursorState {173 let lineNumber = cursor.position.lineNumber;174 let minColumn = model.getLineMinColumn(lineNumber);175 let firstNonBlankColumn = model.getLineFirstNonWhitespaceColumn(lineNumber) || minColumn;176 let column: number;177 let relevantColumnNumber = cursor.position.column;178 if (relevantColumnNumber === firstNonBlankColumn) {179 column = minColumn;180 } else {181 column = firstNonBlankColumn;182 }183 return cursor.move(inSelectionMode, lineNumber, column, 0);184 }185 public static moveToEndOfLine(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean): SingleCursorState {186 let lineNumber = cursor.position.lineNumber;187 let maxColumn = model.getLineMaxColumn(lineNumber);188 return cursor.move(inSelectionMode, lineNumber, maxColumn, 0);189 }190 public static moveToBeginningOfBuffer(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean): SingleCursorState {191 return cursor.move(inSelectionMode, 1, 1, 0);192 }193 public static moveToEndOfBuffer(config: CursorConfiguration, model: ICursorSimpleModel, cursor: SingleCursorState, inSelectionMode: boolean): SingleCursorState {194 let lastLineNumber = model.getLineCount();195 let lastColumn = model.getLineMaxColumn(lastLineNumber);196 return cursor.move(inSelectionMode, lastLineNumber, lastColumn, 0);197 }...
lineNumber.js
Source:lineNumber.js
1/* Any copyright is dedicated to the Public Domain.2 * http://creativecommons.org/licenses/publicdomain/ */3var BUGNUMBER = 1253847;4var summary = 'Line numbers should be updated correctly when a template literal contains CRLF sequences.';5print(BUGNUMBER + ": " + summary);6// lineNumber after template literal.7var base, x, lineno;8eval([9 "base = new Error().lineNumber;",10 "x = `",11 "`;",12 "lineno = new Error().lineNumber;",13].join("\r\n"));14assertEq(lineno, base + 3);15eval([16 "base = new Error().lineNumber;",17 "x = `",18 "",19 "`;",20 "lineno = new Error().lineNumber;",21].join("\r\n"));22assertEq(lineno, base + 4);23eval([24 "base = new Error().lineNumber;",25 "x = `a",26 "b`;",27 "lineno = new Error().lineNumber;",28].join("\r\n"));29assertEq(lineno, base + 3);30// lineNumber inside template literal31eval([32 "base = new Error().lineNumber;",33 "x = `${new Error().lineNumber}",34 "${new Error().lineNumber}",35 "${new Error().lineNumber}`;",36 "lineno = new Error().lineNumber;",37].join("\r\n"));38assertEq(lineno, base + 4);39assertEq(x, (base + 1) + '\n' + (base + 2) + '\n' + (base + 3));40eval([41 "var base = new Error().lineNumber;",42 "var x = `",43 "${new Error().lineNumber}",44 "${new Error().lineNumber}",45 "${new Error().lineNumber}",46 "`;",47 "var lineno = new Error().lineNumber;",48].join("\r\n"));49assertEq(lineno, base + 6);50assertEq(x, '\n' + (base + 2) + '\n' + (base + 3) + '\n' + (base + 4) + '\n');51// When CR, LF, and CRLF are mixed.52eval([53 "var base = new Error().lineNumber;", "\n",54 "var x = `${new Error().lineNumber}", "\n",55 "${new Error().lineNumber}", "\r\n",56 "${new Error().lineNumber}", "\r",57 "${new Error().lineNumber}`;", "\n",58 "var lineno = new Error().lineNumber;",59].join(""));60assertEq(lineno, base + 5);61assertEq(x, (base + 1) + '\n' + (base + 2) + '\n' + (base + 3) + '\n' + (base + 4));62if (typeof reportCompare === "function")...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 for (var i in data.data.runs) {7 var run = data.data.runs[i];8 for (var j in run.firstView) {9 if (j === 'lineNumber') {10 console.log(run.firstView[j]);11 }12 }13 }14 });15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org');18wpt.getTestResults('140411_4M_1M4', function(err, data) {19 if (err) return console.error(err);20 console.log(data);21});22var wpt = require('webpagetest');23var wpt = new WebPageTest('www.webpagetest.org');24 if (err) return console.error(err);25 console.log(data);26});27var wpt = require('webpagetest');28var wpt = new WebPageTest('www.webpagetest.org');29wpt.getTestStatus('140411_4M_1M4', function(err, data) {30 if (err) return console.error(err);31 console.log(data);32});33var wpt = require('webpagetest');34var wpt = new WebPageTest('www.webpagetest.org');35wpt.getLocations(function(err, data) {36 if (err) return console.error(err);37 console.log(data);38});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 wpt.getTestStatus(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data.data);7 });8});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 wpt.getTestResults(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data.data.average.firstView.lineNumber);7 });8});
Using AI Code Generation
1var wpt = require('wpt');2wpt.getTestResults('testId', function(err, data) {3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9var wpt = require('wpt');10wpt.getTestResults('testId', function(err, data) {11 if (err) {12 console.log(err);13 } else {14 console.log(data);15 }16});17var wpt = require('wpt');18wpt.getTestResults('testId', function(err, data) {19 if (err) {20 console.log(err);21 } else {22 console.log(data);23 }24});25var wpt = require('wpt');26wpt.getTestResults('testId', function(err, data) {27 if (err) {28 console.log(err);29 } else {30 console.log(data);31 }32});33var wpt = require('wpt');34wpt.getTestResults('testId', function(err, data) {35 if (err) {36 console.log(err);37 } else {38 console.log(data);39 }40});41var wpt = require('wpt');42wpt.getTestResults('testId', function(err, data) {43 if (err) {44 console.log(err);45 } else {46 console.log(data);47 }48});49var wpt = require('wpt');50wpt.getTestResults('testId', function(err, data) {51 if (err) {52 console.log(err);53 } else {54 console.log(data);55 }56});57var wpt = require('wpt');58wpt.getTestResults('testId', function(err, data) {59 if (err) {60 console.log(err);61 } else {62 console.log(data);63 }64});
Using AI Code Generation
1var wpt = require('web-page-test');2var wpt = new WebPageTest('www.webpagetest.org');3var options = {4};5 if (err) return console.log(err);6 console.log(data);7 wpt.getTestResults(data.data.testId, function(err, data) {8 if (err) return console.log(err);9 console.log(data);10 wpt.getTestResults(data.data.testId, function(err, data) {11 if (err) return console.log(err);12 console.log(data);13 wpt.getTestResults(data.data.testId, function(err, data) {14 if (err) return console.log(err);15 console.log(data);16 wpt.getTestResults(data.data.testId, function(err, data) {17 if (err) return console.log(err);18 console.log(data);19 wpt.getTestResults(data.data.testId, function(err, data) {20 if (err) return console.log(err);21 console.log(data);22 wpt.getTestResults(data.data.testId, function(err, data) {23 if (err) return console.log(err);24 console.log(data);25 wpt.getTestResults(data.data.testId, function(err, data) {26 if (err) return console.log(err);27 console.log(data);28 wpt.getTestResults(data.data.testId, function(err, data) {29 if (err) return console.log(err);30 console.log(data);31 wpt.getTestResults(data.data.testId, function(err, data) {32 if (err) return console.log(err);33 console.log(data);34 wpt.getTestResults(data.data.testId, function(err, data) {35 if (err) return console.log(err);36 console.log(data);37 wpt.getTestResults(data.data.testId, function(err, data) {38 if (err) return console.log(err);39 console.log(data);40 wpt.getTestResults(data.data.testId, function(err, data) {41 if (err) return console.log(err);
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getTestStatus('150111_1D_1da', function(err, data) {4 if (err) return console.error(err);5 console.log('Test status for 150111_1D_1da: %j', data);6 wpt.getTestResults('150111_1D_1da', function(err, data) {7 if (err) return console.error(err);8 console.log('Test results for 150111_1D_1da: %j', data);9 wpt.getTestResults('150111_1D_1da', function(err, data) {10 if (err) return console.error(err);11 console.log('Test results for 150111_1D_1da: %j', data);12 });13 });14});15Test status for 150111_1D_1da: {"statusCode":200,"statusText":"Ok","data":{"statusCode":200,"statusText":"Ok","data":{"testId":"150111_1D_1da","ownerKey":"1da","jsonUrl":"http:\/\/www.webpagetest.org\/jsonResult.php?test=150111_1D_1da","xmlUrl":"http:\/\/www.webpagetest.org\/xmlResult\/150111_1D_1da\/","userUrl":"http:\/\/www.webpagetest.org\/result\/150111_1D_1da\/","summaryCSV":"http:\/\/www.webpagetest.org\/result\/150111_1D_1da\/page_data.csv","detailCSV":"http:\/\/www.webpagetest.org\/result\/150111_1D_1da\/requests.csv","breakdownCSV":"http:\/\/www.webpagetest.org\/result\/150111_1D_1da\/breakdown.csv","medianVideo":"http:\/\/www.webpagetest.org\/video\/median\/150111_1D_1da_1_0.mp4","location":"Dulles:Chrome","from":"www.google.com","connectivity":"Cable","bwDown":1000,"bwUp":1000,"latency":28,"plr":0,"completed":1,"testerDNS":"ec2-54-83-5-182.compute-1.amazonaws.com","
Using AI Code Generation
1var wpt = require('wpt');2wpt.lineNumber();3## **wpt.lineNumber()**4var wpt = require('wpt');5wpt.lineNumber();6## **wpt.lineNumber()**7var wpt = require('wpt');8wpt.lineNumber();9## **wpt.lineNumber()**10var wpt = require('wpt');11wpt.lineNumber();12## **wpt.lineNumber()**13var wpt = require('wpt');14wpt.lineNumber();15## **wpt.lineNumber()**16var wpt = require('wpt');17wpt.lineNumber();18## **wpt.lineNumber()**19var wpt = require('wpt');20wpt.lineNumber();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!