Best JavaScript code snippet using wpt
cursorDeleteOperations.js
Source:cursorDeleteOperations.js
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 *--------------------------------------------------------------------------------------------*/5import * as strings from '../../../base/common/strings.js';6import { ReplaceCommand } from '../commands/replaceCommand.js';7import { CursorColumns, EditOperationResult, isQuote } from './cursorCommon.js';8import { MoveOperations } from './cursorMoveOperations.js';9import { Range } from '../core/range.js';10var DeleteOperations = /** @class */ (function () {11 function DeleteOperations() {12 }13 DeleteOperations.deleteRight = function (prevEditOperationType, config, model, selections) {14 var commands = [];15 var shouldPushStackElementBefore = (prevEditOperationType !== 3 /* DeletingRight */);16 for (var i = 0, len = selections.length; i < len; i++) {17 var selection = selections[i];18 var deleteSelection = selection;19 if (deleteSelection.isEmpty()) {20 var position = selection.getPosition();21 var rightOfPosition = MoveOperations.right(config, model, position.lineNumber, position.column);22 deleteSelection = new Range(rightOfPosition.lineNumber, rightOfPosition.column, position.lineNumber, position.column);23 }24 if (deleteSelection.isEmpty()) {25 // Probably at end of file => ignore26 commands[i] = null;27 continue;28 }29 if (deleteSelection.startLineNumber !== deleteSelection.endLineNumber) {30 shouldPushStackElementBefore = true;31 }32 commands[i] = new ReplaceCommand(deleteSelection, '');33 }34 return [shouldPushStackElementBefore, commands];35 };36 DeleteOperations._isAutoClosingPairDelete = function (config, model, selections) {37 if (config.autoClosingBrackets === 'never' && config.autoClosingQuotes === 'never') {38 return false;39 }40 for (var i = 0, len = selections.length; i < len; i++) {41 var selection = selections[i];42 var position = selection.getPosition();43 if (!selection.isEmpty()) {44 return false;45 }46 var lineText = model.getLineContent(position.lineNumber);47 var character = lineText[position.column - 2];48 if (!config.autoClosingPairsOpen.hasOwnProperty(character)) {49 return false;50 }51 if (isQuote(character)) {52 if (config.autoClosingQuotes === 'never') {53 return false;54 }55 }56 else {57 if (config.autoClosingBrackets === 'never') {58 return false;59 }60 }61 var afterCharacter = lineText[position.column - 1];62 var closeCharacter = config.autoClosingPairsOpen[character];63 if (afterCharacter !== closeCharacter) {64 return false;65 }66 }67 return true;68 };69 DeleteOperations._runAutoClosingPairDelete = function (config, model, selections) {70 var commands = [];71 for (var i = 0, len = selections.length; i < len; i++) {72 var position = selections[i].getPosition();73 var deleteSelection = new Range(position.lineNumber, position.column - 1, position.lineNumber, position.column + 1);74 commands[i] = new ReplaceCommand(deleteSelection, '');75 }76 return [true, commands];77 };78 DeleteOperations.deleteLeft = function (prevEditOperationType, config, model, selections) {79 if (this._isAutoClosingPairDelete(config, model, selections)) {80 return this._runAutoClosingPairDelete(config, model, selections);81 }82 var commands = [];83 var shouldPushStackElementBefore = (prevEditOperationType !== 2 /* DeletingLeft */);84 for (var i = 0, len = selections.length; i < len; i++) {85 var selection = selections[i];86 var deleteSelection = selection;87 if (deleteSelection.isEmpty()) {88 var position = selection.getPosition();89 if (config.useTabStops && position.column > 1) {90 var lineContent = model.getLineContent(position.lineNumber);91 var firstNonWhitespaceIndex = strings.firstNonWhitespaceIndex(lineContent);92 var lastIndentationColumn = (firstNonWhitespaceIndex === -193 ? /* entire string is whitespace */ lineContent.length + 194 : firstNonWhitespaceIndex + 1);95 if (position.column <= lastIndentationColumn) {96 var fromVisibleColumn = CursorColumns.visibleColumnFromColumn2(config, model, position);97 var toVisibleColumn = CursorColumns.prevIndentTabStop(fromVisibleColumn, config.indentSize);98 var toColumn = CursorColumns.columnFromVisibleColumn2(config, model, position.lineNumber, toVisibleColumn);99 deleteSelection = new Range(position.lineNumber, toColumn, position.lineNumber, position.column);100 }101 else {102 deleteSelection = new Range(position.lineNumber, position.column - 1, position.lineNumber, position.column);103 }104 }105 else {106 var leftOfPosition = MoveOperations.left(config, model, position.lineNumber, position.column);107 deleteSelection = new Range(leftOfPosition.lineNumber, leftOfPosition.column, position.lineNumber, position.column);108 }109 }110 if (deleteSelection.isEmpty()) {111 // Probably at beginning of file => ignore112 commands[i] = null;113 continue;114 }115 if (deleteSelection.startLineNumber !== deleteSelection.endLineNumber) {116 shouldPushStackElementBefore = true;117 }118 commands[i] = new ReplaceCommand(deleteSelection, '');119 }120 return [shouldPushStackElementBefore, commands];121 };122 DeleteOperations.cut = function (config, model, selections) {123 var commands = [];124 for (var i = 0, len = selections.length; i < len; i++) {125 var selection = selections[i];126 if (selection.isEmpty()) {127 if (config.emptySelectionClipboard) {128 // This is a full line cut129 var position = selection.getPosition();130 var startLineNumber = void 0, startColumn = void 0, endLineNumber = void 0, endColumn = void 0;131 if (position.lineNumber < model.getLineCount()) {132 // Cutting a line in the middle of the model133 startLineNumber = position.lineNumber;134 startColumn = 1;135 endLineNumber = position.lineNumber + 1;136 endColumn = 1;137 }138 else if (position.lineNumber > 1) {139 // Cutting the last line & there are more than 1 lines in the model140 startLineNumber = position.lineNumber - 1;141 startColumn = model.getLineMaxColumn(position.lineNumber - 1);142 endLineNumber = position.lineNumber;143 endColumn = model.getLineMaxColumn(position.lineNumber);144 }145 else {146 // Cutting the single line that the model contains147 startLineNumber = position.lineNumber;148 startColumn = 1;149 endLineNumber = position.lineNumber;150 endColumn = model.getLineMaxColumn(position.lineNumber);151 }152 var deleteSelection = new Range(startLineNumber, startColumn, endLineNumber, endColumn);153 if (!deleteSelection.isEmpty()) {154 commands[i] = new ReplaceCommand(deleteSelection, '');155 }156 else {157 commands[i] = null;158 }159 }160 else {161 // Cannot cut empty selection162 commands[i] = null;163 }164 }165 else {166 commands[i] = new ReplaceCommand(selection, '');167 }168 }169 return new EditOperationResult(0 /* Other */, commands, {170 shouldPushStackElementBefore: true,171 shouldPushStackElementAfter: true172 });173 };174 return DeleteOperations;175}());...
cursorDeleteOperations.ts
Source:cursorDeleteOperations.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 { ReplaceCommand } from 'vs/editor/common/commands/replaceCommand';7import { CursorColumns, CursorConfiguration, ICursorSimpleModel, EditOperationResult } from 'vs/editor/common/controller/cursorCommon';8import { Range } from 'vs/editor/common/core/range';9import { Selection } from 'vs/editor/common/core/selection';10import { MoveOperations } from 'vs/editor/common/controller/cursorMoveOperations';11import * as strings from 'vs/base/common/strings';12import { ICommand } from 'vs/editor/common/editorCommon';13export class DeleteOperations {14 public static deleteRight(config: CursorConfiguration, model: ICursorSimpleModel, selections: Selection[]): [boolean, ICommand[]] {15 let commands: ICommand[] = [];16 let shouldPushStackElementBefore = false;17 for (let i = 0, len = selections.length; i < len; i++) {18 const selection = selections[i];19 let deleteSelection: Range = selection;20 if (deleteSelection.isEmpty()) {21 let position = selection.getPosition();22 let rightOfPosition = MoveOperations.right(config, model, position.lineNumber, position.column);23 deleteSelection = new Range(24 rightOfPosition.lineNumber,25 rightOfPosition.column,26 position.lineNumber,27 position.column28 );29 }30 if (deleteSelection.isEmpty()) {31 // Probably at end of file => ignore32 commands[i] = null;33 continue;34 }35 if (deleteSelection.startLineNumber !== deleteSelection.endLineNumber) {36 shouldPushStackElementBefore = true;37 }38 commands[i] = new ReplaceCommand(deleteSelection, '');39 }40 return [shouldPushStackElementBefore, commands];41 }42 private static _isAutoClosingPairDelete(config: CursorConfiguration, model: ICursorSimpleModel, selections: Selection[]): boolean {43 if (!config.autoClosingBrackets) {44 return false;45 }46 for (let i = 0, len = selections.length; i < len; i++) {47 const selection = selections[i];48 const position = selection.getPosition();49 if (!selection.isEmpty()) {50 return false;51 }52 const lineText = model.getLineContent(position.lineNumber);53 const character = lineText[position.column - 2];54 if (!config.autoClosingPairsOpen.hasOwnProperty(character)) {55 return false;56 }57 const afterCharacter = lineText[position.column - 1];58 const closeCharacter = config.autoClosingPairsOpen[character];59 if (afterCharacter !== closeCharacter) {60 return false;61 }62 }63 return true;64 }65 private static _runAutoClosingPairDelete(config: CursorConfiguration, model: ICursorSimpleModel, selections: Selection[]): [boolean, ICommand[]] {66 let commands: ICommand[] = [];67 for (let i = 0, len = selections.length; i < len; i++) {68 const position = selections[i].getPosition();69 const deleteSelection = new Range(70 position.lineNumber,71 position.column - 1,72 position.lineNumber,73 position.column + 174 );75 commands[i] = new ReplaceCommand(deleteSelection, '');76 }77 return [true, commands];78 }79 public static deleteLeft(config: CursorConfiguration, model: ICursorSimpleModel, selections: Selection[]): [boolean, ICommand[]] {80 if (this._isAutoClosingPairDelete(config, model, selections)) {81 return this._runAutoClosingPairDelete(config, model, selections);82 }83 let commands: ICommand[] = [];84 let shouldPushStackElementBefore = false;85 for (let i = 0, len = selections.length; i < len; i++) {86 const selection = selections[i];87 let deleteSelection: Range = selection;88 if (deleteSelection.isEmpty()) {89 let position = selection.getPosition();90 if (config.useTabStops && position.column > 1) {91 let lineContent = model.getLineContent(position.lineNumber);92 let firstNonWhitespaceIndex = strings.firstNonWhitespaceIndex(lineContent);93 let lastIndentationColumn = (94 firstNonWhitespaceIndex === -195 ? /* entire string is whitespace */lineContent.length + 196 : firstNonWhitespaceIndex + 197 );98 if (position.column <= lastIndentationColumn) {99 let fromVisibleColumn = CursorColumns.visibleColumnFromColumn2(config, model, position);100 let toVisibleColumn = CursorColumns.prevTabStop(fromVisibleColumn, config.tabSize);101 let toColumn = CursorColumns.columnFromVisibleColumn2(config, model, position.lineNumber, toVisibleColumn);102 deleteSelection = new Range(position.lineNumber, toColumn, position.lineNumber, position.column);103 } else {104 deleteSelection = new Range(position.lineNumber, position.column - 1, position.lineNumber, position.column);105 }106 } else {107 let leftOfPosition = MoveOperations.left(config, model, position.lineNumber, position.column);108 deleteSelection = new Range(109 leftOfPosition.lineNumber,110 leftOfPosition.column,111 position.lineNumber,112 position.column113 );114 }115 }116 if (deleteSelection.isEmpty()) {117 // Probably at beginning of file => ignore118 commands[i] = null;119 continue;120 }121 if (deleteSelection.startLineNumber !== deleteSelection.endLineNumber) {122 shouldPushStackElementBefore = true;123 }124 commands[i] = new ReplaceCommand(deleteSelection, '');125 }126 return [shouldPushStackElementBefore, commands];127 }128 public static cut(config: CursorConfiguration, model: ICursorSimpleModel, selections: Selection[]): EditOperationResult {129 let commands: ICommand[] = [];130 for (let i = 0, len = selections.length; i < len; i++) {131 const selection = selections[i];132 if (selection.isEmpty()) {133 if (config.emptySelectionClipboard) {134 // This is a full line cut135 let position = selection.getPosition();136 let startLineNumber: number,137 startColumn: number,138 endLineNumber: number,139 endColumn: number;140 if (position.lineNumber < model.getLineCount()) {141 // Cutting a line in the middle of the model142 startLineNumber = position.lineNumber;143 startColumn = 1;144 endLineNumber = position.lineNumber + 1;145 endColumn = 1;146 } else if (position.lineNumber > 1) {147 // Cutting the last line & there are more than 1 lines in the model148 startLineNumber = position.lineNumber - 1;149 startColumn = model.getLineMaxColumn(position.lineNumber - 1);150 endLineNumber = position.lineNumber;151 endColumn = model.getLineMaxColumn(position.lineNumber);152 } else {153 // Cutting the single line that the model contains154 startLineNumber = position.lineNumber;155 startColumn = 1;156 endLineNumber = position.lineNumber;157 endColumn = model.getLineMaxColumn(position.lineNumber);158 }159 let deleteSelection = new Range(160 startLineNumber,161 startColumn,162 endLineNumber,163 endColumn164 );165 if (!deleteSelection.isEmpty()) {166 commands[i] = new ReplaceCommand(deleteSelection, '');167 } else {168 commands[i] = null;169 }170 } else {171 // Cannot cut empty selection172 commands[i] = null;173 }174 } else {175 commands[i] = new ReplaceCommand(selection, '');176 }177 }178 return new EditOperationResult(commands, {179 shouldPushStackElementBefore: true,180 shouldPushStackElementAfter: true181 });182 }...
macros.js
Source:macros.js
...4//5// Some utility function for the use of macros and autosubstitute6function showhelp()7{8 deleteSelection();9 document.getElementById('helpmenu').open=true;10}11function showhelpsystem()12{13 msiGoDoCommand('cmd_help_contents');14}15function findNext()16{17 msiGoDoCommand('cmd_findNext');18}19function findPrev()20{21 msiGoDoCommand('cmd_findPrev');22}23function deleteSelection()24{25 var theEditorElement = msiGetActiveEditorElement();26 var editor = msiGetEditor(theEditorElement);27 editor.selection.deleteFromDocument();28}29function getCurrentEditorElement()30{31 var theEditorElement = msiGetActiveEditorElement();32 return theEditorElement;33}34function define()35{36 doComputeCommand('cmd_compute_Define');37}38function insertMathSymbol( s, delSelection )39{40// if (delSelection) deleteSelection();41 dump("\ninsertMathSymbol(" + s + ")");42 doParamCommand('cmd_MSIsymbolCmd',s);43}44function insertMathOperator(aName, limitPlacement, size, editorElement) {45 return doInsertMathOperator(aName, limitPlacement, size, editorElement);46}47function doInsertMathunit( unit, delSelection )48{49 var editorElement = getCurrentEditorElement();50// if (delSelection) deleteSelection();51 insertmathunit(unit, editorElement);52}53function doInsertMathname( name, delSelection )54{55 var editorElement = getCurrentEditorElement();56// if (delSelection) deleteSelection();57 insertmathname(name, editorElement);58}59function insertTag( name, delSelection )60{61 var editorElement = getCurrentEditorElement();62 var editor = msiGetEditor(editorElement);63 var HTMLEditor = editor.QueryInterface(Components.interfaces.nsIHTMLEditor);64 if (delSelection) deleteSelection();65 var tagclass = editor.tagListManager.getRealClassOfTag(name, null);66 var cmd = "";67 switch (tagclass) {68 case "texttag" : cmd = "cmd_texttag";69 break;70 case "paratag" :71 case "listtag" : cmd = "cmd_paratag";72 break;73 case "structtag":74 case "envtag" : cmd = "cmd_structtag";75 break;76 default:77 }78 if (cmd !== "")79 msiDoStatefulCommand(cmd,name);80}81function insertText ( textString )82{83 var editorElement = getCurrentEditorElement();84 var editor = msiGetEditor(editorElement);85 var plaintextEditor = editor.QueryInterface(Components.interfaces.nsIPlaintextEditor);86 plaintextEditor.insertText( textString);87}88function checkSpelling(delSelection)89{90 if (delSelection) deleteSelection();91 msiGoDoCommand('cmd_spelling');92}93function toggleTextTag( tagname, delSelection )94{95 if (delSelection) deleteSelection();96 msiDoStatefulCommand('cmd_texttag', tagname );97}98function insertParaTag( tagname, delSelection )99{100 if (delSelection) deleteSelection();101 msiDoStatefulCommand('cmd_paratag', tagname );102}103function insertSectionTag( tagname, delSelection )104{105 if (delSelection) deleteSelection();106 msiDoStatefulCommand('cmd_structtag', tagname );107}108function insertListItem( tagname, delSelection )109{110 if (delSelection) deleteSelection();111 msiDoStatefulCommand('cmd_paratag', tagname );112}113function insertFrontMatterItem( tagname, delSelection)114{115 if (delSelection) deleteSelection();116 msiDoStatefulCommand('cmd_frontmtag', tagname );117}118function yell ( textString, delSelection )119{120 if (delSelection) deleteSelection();121 alert(textString);122}123function insertFragmentOrMacro( name, delSelection )124{125 if (delSelection) deleteSelection();126 onMacroOrFragmentEntered( name );127}128function previewPDF(delSelection)129{130 if (delSelection) deleteSelection();131 printTeX(true,true);132}133function previewDVI(delSelection)134{135 if (delSelection) deleteSelection();136 printTeX(false,true);137}138function insertFootnote(delSelection)139{140 if (delSelection) deleteSelection();141 var editorElement = getCurrentEditorElement();142 msiNote(null, editorElement, 'footnote', false);143}144function insertMarginNote(delSelection)145{146 if (delSelection) deleteSelection();147 var editorElement = getCurrentEditorElement();148 msiNote(null, editorElement, 'marginnote',false);149}150function softSave(delSelection)151{152 if (delSelection) deleteSelection();153 msiGoDoCommand('cmd_softSave');154}155function insertIntegral(delSelection)156{157 dump("\ninsertIntegeral\n");158// if (delSelection) deleteSelection();159 insertMathSymbol("\u222B");160 insertMathSymbol("\u2146");161 insertText('x');162 //msiGoDoCommand('cmd_charPrevious');163 //msiGoDoCommand('cmd_charPrevious');164}165function insertSubstructure(delSelection)166{167 if (delSelection) deleteSelection();168 msiGoDoCommand('cmd_insertSubstructure');169}170function unnumberSection()171{172 deleteSelection();173 var editorElement = getCurrentEditorElement();174 var editor = msiGetEditor(editorElement);175 176 var section = editor.selection.anchorNode;177 while (section && section.nodeName != 'section' && section.nodeName != 'subsection' && section.nodeName != 'subsubsection') {178 section = section.parentNode;179 }180// alert(section.nodeName);181 if (section) section.setAttribute("nonum","true");182}183function renumberSection()184{185 deleteSelection();186 var editorElement = getCurrentEditorElement();187 var editor = msiGetEditor(editorElement);188 189 var section = editor.selection.anchorNode;190 while (section && section.nodeName != 'section' && section.nodeName != 'subsection' && section.nodeName != 'subsubsection') {191 section = section.parentNode;192 }193// alert(section.nodeName);194 if (section) section.removeAttribute("nonum");195}196function convertSelectionToMathName() {197 var editorElement = msiGetActiveEditorElement();198 var editor = msiGetEditor(editorElement);199 var name = editor.selection.toString();200 deleteSelection();201 doInsertMathname(name, true);...
Using AI Code Generation
1var editor = CKEDITOR.instances.editor1;2editor.on( 'instanceReady', function( evt ) {3 var editor = evt.editor;4 editor.document.on( 'keydown', function( evt ) {5 if ( evt.data.$.keyCode === CKEDITOR.CTRL + 8 /* BACKSPACE */ ) {6 editor.execCommand( 'deleteSelection' );7 evt.cancel();8 }9 } );10} );11CKEDITOR.editorConfig = function( config ) {12 config.extraPlugins = 'wptextpattern';13};14CKEDITOR.plugins.add( 'wptextpattern', {15 init: function( editor ) {16 editor.addCommand( 'deleteSelection', {17 exec: function( editor ) {18 editor.document.$.execCommand( 'delete', false, null );19 }20 } );21 }22} );
Using AI Code Generation
1var wptab = Components.classes["@mozilla.org/webpagetabs;1"].getService(Components.interfaces.nsIWebPageTabs);2wptab.deleteSelection();3var wptab = Components.classes["@mozilla.org/webpagetabs;1"].getService(Components.interfaces.nsIWebPageTabs);4wptab.select();5var wptab = Components.classes["@mozilla.org/webpagetabs;1"].getService(Components.interfaces.nsIWebPageTabs);6wptab.select();7var wptab = Components.classes["@mozilla.org/webpagetabs;1"].getService(Components.interfaces.nsIWebPageTabs);8var wptab = Components.classes["@mozilla.org/webpagetabs;1"].getService(Components.interfaces.nsIWebPageTabs);9var wptab = Components.classes["@mozilla.org/webpagetabs;1"].getService(Components.interfaces.nsIWebPageTabs);10var wptab = Components.classes["@mozilla.org/webpagetabs;1"].getService(Components.interfaces.nsIWebPageTabs);
Using AI Code Generation
1var editor = new WpTextEditor("editor");2editor.deleteSelection();3WpTextEditor.prototype.deleteSelection = function(){4 var selection = this.getSelection();5 var range = selection.getRangeAt(0);6 range.deleteContents();7};
Using AI Code Generation
1var editor = CKEDITOR.instances.editor1;2editor.execCommand('deleteSelection');3var editor = CKEDITOR.instances.editor1;4editor.execCommand('deleteSelection');5var editor = CKEDITOR.instances.editor1;6editor.focus();7var editor = CKEDITOR.instances.editor1;8editor.execCommand('deleteSelection');9var editor = CKEDITOR.instances.editor1;10editor.focus();11var editor = CKEDITOR.instances.editor1;12editor.execCommand('deleteSelection');13var editor = CKEDITOR.instances.editor1;14editor.focus();15var editor = CKEDITOR.instances.editor1;16editor.execCommand('deleteSelection');
Using AI Code Generation
1var wpText = document.getElementById( 'wpTextbox1' );2var deleteSelection = wpText.deleteSelection;3deleteSelection( 'this' );4function deleteSelection( text ) {5}6mw.WikiEditor.prototype.deleteSelection = function ( text ) {7};8mw.WikiEditor.prototype.deleteSelection = function ( text ) {9 selection = this.selection;10};11mw.WikiEditor.prototype.deleteSelection = function ( text ) {12 selection = this.selection;13 selection.replaceSelection( '' );14};15mw.WikiEditor.prototype.deleteSelection = function ( text ) {16 selection = this.selection;17 selection.replaceSelection( '' );18 textarea.focus();19};20mw.WikiEditor.prototype.deleteSelection = function ( text ) {21 selection = this.selection;22 selection.replaceSelection( '' );23 textarea.focus();24 textarea.scrollTop = scrollTop;25};26mw.WikiEditor.prototype.deleteSelection = function ( text ) {27 selection = this.selection;28 selection.replaceSelection( '' );29 textarea.focus();
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!!