Replace _textSelectionStart and _textSelectionEnd with SimpleRectangle(s).

Also move them into their sections.

Signed-off-by: Gökay Şatır <gokaysatir@collabora.com>
Change-Id: I677a100c859ac8986f5609d9caa5187ef81818dd
pull/9012/head
Gökay Şatır 2024-05-02 13:19:13 +03:00 committed by Gökay ŞATIR
parent b9e7d071a2
commit ecdcc369d6
3 changed files with 21 additions and 20 deletions

View File

@ -3509,17 +3509,16 @@ L.CanvasTileLayer = L.Layer.extend({
if (rectangles.length) {
var topLeftTwips = rectangles[0].getTopLeft();
var bottomRightTwips = rectangles[0].getBottomRight();
var oldSelection = this._textSelectionEnd;
this._textSelectionEnd = new L.LatLngBounds(
this._twipsToLatLng(topLeftTwips, this._map.getZoom()),
this._twipsToLatLng(bottomRightTwips, this._map.getZoom()));
var oldSelection = this._selectionHandles.end.rectangle ? this._selectionHandles.end.rectangle.clone(): null;
this._updateScrollOnCellSelection(oldSelection, this._textSelectionEnd);
this._selectionHandles.end.rectangle = new app.definitions.simpleRectangle(topLeftTwips.x, topLeftTwips.y, (bottomRightTwips.x - topLeftTwips.x), (bottomRightTwips.y - topLeftTwips.y));
this._updateScrollOnCellSelection(oldSelection, this._selectionHandles.end.rectangle);
this._selectionHandles.end.setShowSection(true);
this._updateMarkers();
}
else {
this._textSelectionEnd = null;
this._selectionHandles.end.rectangle = null;
}
},
@ -3529,21 +3528,19 @@ L.CanvasTileLayer = L.Layer.extend({
if (rectangles.length) {
var topLeftTwips = rectangles[0].getTopLeft();
var bottomRightTwips = rectangles[0].getBottomRight();
var oldSelection = this._textSelectionStart;
let oldSelection = this._selectionHandles.start.rectangle ? this._selectionHandles.start.rectangle.clone(): null;
//FIXME: The selection is really not two points, as they can be
//FIXME: on top of each other, but on separate lines. We should
//FIXME: capture the whole area in _onTextSelectionMsg.
this._textSelectionStart = new L.LatLngBounds(
this._twipsToLatLng(topLeftTwips, this._map.getZoom()),
this._twipsToLatLng(bottomRightTwips, this._map.getZoom()));
this._selectionHandles.start.rectangle = new app.definitions.simpleRectangle(topLeftTwips.x, topLeftTwips.y, (bottomRightTwips.x - topLeftTwips.x), (bottomRightTwips.y - topLeftTwips.y));
this._updateScrollOnCellSelection(oldSelection, this._textSelectionStart);
this._updateScrollOnCellSelection(oldSelection, this._selectionHandles.start.rectangle);
this._selectionHandles.start.setShowSection(true);
this._selectionHandles.active = true;
}
else {
this._textSelectionStart = null;
this._selectionHandles.start.rectangle = null;
}
},
@ -4788,8 +4785,8 @@ L.CanvasTileLayer = L.Layer.extend({
},
_removeSelection: function() {
this._textSelectionStart = null;
this._textSelectionEnd = null;
this._selectionHandles.start.rectangle = null;
this._selectionHandles.end.rectangle = null;
this._selectedTextContent = '';
this._selectionHandles.start.setShowSection(false);
@ -4800,14 +4797,14 @@ L.CanvasTileLayer = L.Layer.extend({
},
_updateMarkers: function() {
if (!app.file.textCursor.visible || !this._textSelectionStart)
if (!app.file.textCursor.visible || !this._selectionHandles.start.rectangle)
return;
if (!this._selectionHandles.start.isSectionShown() || !this._selectionHandles.end.isSectionShown())
return;
var startPos = this._map._docLayer._latLngToCorePixels(this._textSelectionStart.getSouthWest());
var endPos = this._map._docLayer._latLngToCorePixels(this._textSelectionEnd.getSouthWest());
var startPos = { x: this._selectionHandles.start.rectangle.pX1, y: this._selectionHandles.start.rectangle.pY2 };
var endPos = { x: this._selectionHandles.end.rectangle.pX1, y: this._selectionHandles.end.rectangle.pY2 };
if (app.map._docLayer.isCalcRTL()) {
// Mirror position from right to left.

View File

@ -10,6 +10,7 @@
*/
class TextSelectionHandle extends HTMLObjectSection {
public rectangle: cool.SimpleRectangle = null; // This is the rectangle sent from the core side.
constructor (sectionName: string, objectWidth: number, objectHeight: number, documentPosition: cool.SimplePoint, extraClass: string = "", visible: boolean = true) {
super(sectionName, objectWidth, objectHeight, documentPosition, extraClass, visible);

View File

@ -278,10 +278,13 @@ L.Map.TouchGesture = L.Handler.extend({
if (app.calc.cellCursorVisible)
bContainsSel = docLayer.containsSelection(latlng);
var textSelection;
if (docLayer._textSelectionStart && docLayer._textSelectionEnd)
textSelection = new L.LatLngBounds(docLayer._textSelectionStart.getSouthWest(), docLayer._textSelectionEnd.getNorthEast());
if (docLayer._selectionHandles.start.rectangle && docLayer._selectionHandles.end.rectangle) {
// Oversimplication. See "inBand" function.
textSelection = new app.definitions.simpleRectangle(0, docLayer._selectionHandles.end.rectangle.y1, app.file.size.twips[0], 0);
textSelection.height = docLayer._selectionHandles.end.rectangle.y2 - docLayer._selectionHandles.start.rectangle.y1;
}
if ((textSelection && textSelection.inBand(latlng))
if ((textSelection && textSelection.pContainsPoint(posInTwips.toArray()))
|| (graphicSelection && graphicSelection.contains(latlng))
|| (app.calc.cellCursorVisible && app.calc.cellCursorRectangle.containsPoint(posInTwips.toArray())) || bContainsSel) {
// long touched an already selected object