Files
react-native-devtools-frontend/front_end/text_utils/TextCursor.js
T
Tim van der Lippe 2e38eeaf9f Remove all comments with only the unrestricted annotation
The unrestricted annotation is Closure-specific and can be removed.
This patch removes all comments with only the unrestricted annotation
in them.

R=szuend@chromium.org

No-Presubmit: True
Bug: 1011811
Change-Id: Iba0723644f53f5307c3077d341271af86becc32a
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2569758
Commit-Queue: Tim van der Lippe <tvanderlippe@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
Auto-Submit: Tim van der Lippe <tvanderlippe@chromium.org>
2020-12-02 15:25:32 +00:00

57 lines
1.2 KiB
JavaScript

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
export class TextCursor {
/**
* @param {!Array<number>} lineEndings
*/
constructor(lineEndings) {
this._lineEndings = lineEndings;
this._offset = 0;
this._lineNumber = 0;
this._columnNumber = 0;
}
/**
* @param {number} offset
*/
advance(offset) {
this._offset = offset;
while (this._lineNumber < this._lineEndings.length && this._lineEndings[this._lineNumber] < this._offset) {
++this._lineNumber;
}
this._columnNumber = this._lineNumber ? this._offset - this._lineEndings[this._lineNumber - 1] - 1 : this._offset;
}
/**
* @return {number}
*/
offset() {
return this._offset;
}
/**
* @param {number} offset
*/
resetTo(offset) {
this._offset = offset;
this._lineNumber = this._lineEndings.lowerBound(offset);
this._columnNumber = this._lineNumber ? this._offset - this._lineEndings[this._lineNumber - 1] - 1 : this._offset;
}
/**
* @return {number}
*/
lineNumber() {
return this._lineNumber;
}
/**
* @return {number}
*/
columnNumber() {
return this._columnNumber;
}
}