Files
azuredatastudio/extensions/notebook/src/intellisense/text.ts
Karl Burtram 8a3d08f0de Merge vscode 1.67 (#20883)
* Fix initial build breaks from 1.67 merge (#2514)

* Update yarn lock files

* Update build scripts

* Fix tsconfig

* Build breaks

* WIP

* Update yarn lock files

* Misc breaks

* Updates to package.json

* Breaks

* Update yarn

* Fix breaks

* Breaks

* Build breaks

* Breaks

* Breaks

* Breaks

* Breaks

* Breaks

* Missing file

* Breaks

* Breaks

* Breaks

* Breaks

* Breaks

* Fix several runtime breaks (#2515)

* Missing files

* Runtime breaks

* Fix proxy ordering issue

* Remove commented code

* Fix breaks with opening query editor

* Fix post merge break

* Updates related to setup build and other breaks (#2516)

* Fix bundle build issues

* Update distro

* Fix distro merge and update build JS files

* Disable pipeline steps

* Remove stats call

* Update license name

* Make new RPM dependencies a warning

* Fix extension manager version checks

* Update JS file

* Fix a few runtime breaks

* Fixes

* Fix runtime issues

* Fix build breaks

* Update notebook tests (part 1)

* Fix broken tests

* Linting errors

* Fix hygiene

* Disable lint rules

* Bump distro

* Turn off smoke tests

* Disable integration tests

* Remove failing "activate" test

* Remove failed test assertion

* Disable other broken test

* Disable query history tests

* Disable extension unit tests

* Disable failing tasks
2022-10-19 19:13:18 -07:00

72 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.
// This code is originally from @jupyterlab/packages/coreutils/src/text.ts
// Note: this code doesn't seem to do anything in the sqlops environment since the
// surr
// javascript stores text as utf16 and string indices use "code units",
// which stores high-codepoint characters as "surrogate pairs",
// which occupy two indices in the javascript string.
// We need to translate cursor_pos in the Jupyter protocol (in characters)
// to js offset (with surrogate pairs taking two spots).
// allow-any-unicode-next-line
const HAS_SURROGATES: boolean = '𝐚'.length > 1;
/**
* Convert a javascript string index into a unicode character offset
*
* @param jsIdx - The javascript string index (counting surrogate pairs)
*
* @param text - The text in which the offset is calculated
*
* @returns The unicode character offset
*/
export function jsIndexToCharIndex(jsIdx: number, text: string): number {
if (!HAS_SURROGATES) {
// not using surrogates, nothing to do
return jsIdx;
}
let charIdx = jsIdx;
for (let i = 0; i + 1 < text.length && i < jsIdx; i++) {
let charCode = text.charCodeAt(i);
// check for surrogate pair
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
let nextCharCode = text.charCodeAt(i + 1);
if (nextCharCode >= 0xDC00 && nextCharCode <= 0xDFFF) {
charIdx--;
i++;
}
}
}
return charIdx;
}
/**
* Get the diff between pure character count and JS-based count with 2 chars per surrogate pair.
*
* @param text - The text in which the offset is calculated
*
* @returns The js-native index
*/
export function charCountToJsCountDiff(text: string): number {
let diff = 0;
if (!HAS_SURROGATES) {
// not using surrogates, nothing to do
return diff;
}
for (let i = 0; i + 1 < text.length; i++) {
let charCode = text.charCodeAt(i);
// check for surrogate pair
if (charCode >= 0xD800 && charCode <= 0xDBFF) {
let nextCharCode = text.charCodeAt(i + 1);
if (nextCharCode >= 0xDC00 && nextCharCode <= 0xDFFF) {
diff++;
i++;
}
}
}
return diff;
}