[Libreoffice-commits] online.git: Branch 'distro/collabora/milestone-7' - loleaflet/src
Ozcan Esen
ozcan.esen at collabora.com
Mon Jan 18 01:20:11 PST 2016
loleaflet/src/control/Parts.js | 1
loleaflet/src/control/Search.js | 23 ++++++++++++
loleaflet/src/layer/tile/TileLayer.js | 65 +++++++++++++++++++++++++++++++++-
3 files changed, 88 insertions(+), 1 deletion(-)
New commits:
commit 16ecef517679a903bbedcd42ff935d4e693fa2cf
Author: Ozcan Esen <ozcan.esen at collabora.com>
Date: Thu Jan 14 22:11:12 2016 +0200
loleaflet: new searchAll for presentation
does not affect regular searches since it caches results only if
(this._docType === 'presentation' && count > 1) and clears cache on
mousedown
Change-Id: I5569424df6e463da0c63166eef36842fa7d32f0e
diff --git a/loleaflet/src/control/Parts.js b/loleaflet/src/control/Parts.js
index 0183196..8d41779 100644
--- a/loleaflet/src/control/Parts.js
+++ b/loleaflet/src/control/Parts.js
@@ -41,6 +41,7 @@ L.Map.include({
if (docLayer._docType === 'spreadsheet') {
this._socket.sendMessage('commandvalues command=.uno:ViewRowColumnHeaders');
}
+ docLayer._drawSearchResuls();
},
getPreview: function (id, index, maxWidth, maxHeight, options) {
diff --git a/loleaflet/src/control/Search.js b/loleaflet/src/control/Search.js
index bf14a13..136f97b 100644
--- a/loleaflet/src/control/Search.js
+++ b/loleaflet/src/control/Search.js
@@ -7,6 +7,28 @@ L.Map.include({
all = 0;
}
+ // check if there is a cached searchAll result for this phrase
+ // if there is update index for next/prev iteration
+ if (this._docLayer._searchResults && text === this._docLayer._searchTerm) {
+ if (backward) {
+ if (this._docLayer._searchIndex > 0) {
+ this._docLayer._searchIndex--;
+ }
+ else {
+ this._docLayer._searchIndex = this._docLayer._searchResults.length - 1;
+ }
+ } else {
+ if (this._docLayer._searchIndex < this._docLayer._searchResults.length - 1) {
+ this._docLayer._searchIndex++;
+ }
+ else {
+ this._docLayer._searchIndex = 0;
+ }
+ }
+ this.setPart(this._docLayer._searchResults[this._docLayer._searchIndex].part);
+ return;
+ }
+
var searchCmd = {
'SearchItem.SearchString': {
'type': 'string'
@@ -43,6 +65,7 @@ L.Map.include({
},
resetSelection: function () {
+ this._docLayer._clearSearchResults();
this._socket.sendMessage('resetselection');
}
});
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 0f0d2eb..9f6a673 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -111,6 +111,9 @@ L.TileLayer = L.GridLayer.extend({
this._selections = new L.LayerGroup();
map.addLayer(this._selections);
+ this._searchResultsLayer = new L.LayerGroup();
+ map.addLayer(this._searchResultsLayer);
+
this._levels = {};
this._tiles = {};
this._tileCache = {};
@@ -472,11 +475,13 @@ L.TileLayer = L.GridLayer.extend({
},
_onSearchNotFoundMsg: function (textMsg) {
+ this._clearSearchResults();
var originalPhrase = textMsg.substring(16);
this._map.fire('search', {originalPhrase: originalPhrase, count: 0});
},
_onSearchResultSelection: function (textMsg) {
+ this._clearSearchResults();
textMsg = textMsg.substring(23);
var obj = JSON.parse(textMsg);
var originalPhrase = obj.searchString;
@@ -485,12 +490,66 @@ L.TileLayer = L.GridLayer.extend({
for (var i = 0; i < obj.searchResultSelection.length; i++) {
results.push({
part: parseInt(obj.searchResultSelection[i].part),
- rectangles: this._twipsRectanglesToPixelBounds(obj.searchResultSelection[i].rectangles)
+ rectangles: this._twipsRectanglesToPixelBounds(obj.searchResultSelection[i].rectangles),
+ twipsRectangles: obj.searchResultSelection[i].rectangles
});
}
+ // do not cache search results if there is only one result.
+ // this way regular searches works fine
+ if (this._docType === 'presentation' && count > 1)
+ {
+ this._map._socket.sendMessage('resetselection');
+ this._searchResults = results;
+ this._searchTerm = originalPhrase;
+ this._searchIndex = 0;
+
+ this._map.setPart(results[0].part); // go to first result.
+ }
this._map.fire('search', {originalPhrase: originalPhrase, count: count, results: results});
},
+ _clearSearchResults: function() {
+ this._searchResults = null;
+ this._searchTerm = null;
+ this._searchIndex = null;
+ this._searchResultsLayer.clearLayers();
+ },
+
+ _drawSearchResuls: function() {
+ if (!this._searchResults) {
+ return;
+ }
+ this._searchResultsLayer.clearLayers();
+ for (var k=0; k < this._searchResults.length; k++)
+ {
+ var result = this._searchResults[k];
+ if (result.part === this._selectedPart)
+ {
+ var _fillColor = (k === this._searchIndex) ? '#43ACE8' : '#CCCCCC';
+ var strTwips = result.twipsRectangles.match(/\d+/g);
+ var rectangles = [];
+ for (var i = 0; i < strTwips.length; i += 4) {
+ var topLeftTwips = new L.Point(parseInt(strTwips[i]), parseInt(strTwips[i + 1]));
+ var offset = new L.Point(parseInt(strTwips[i + 2]), parseInt(strTwips[i + 3]));
+ var topRightTwips = topLeftTwips.add(new L.Point(offset.x, 0));
+ var bottomLeftTwips = topLeftTwips.add(new L.Point(0, offset.y));
+ var bottomRightTwips = topLeftTwips.add(offset);
+ rectangles.push([bottomLeftTwips, bottomRightTwips, topLeftTwips, topRightTwips]);
+ }
+ var polygons = L.PolyUtil.rectanglesToPolygons(rectangles, this);
+ for (var j = 0; j < polygons.length; j++) {
+ var selection = new L.Polygon(polygons[j], {
+ pointerEvents: 'none',
+ fillColor: _fillColor,
+ fillOpacity: 0.25,
+ weight: 2,
+ opacity: 0.25});
+ this._searchResultsLayer.addLayer(selection);
+ }
+ }
+ }
+ },
+
_onStateChangedMsg: function (textMsg) {
var unoMsg = textMsg.substr(14).split('=');
var commandName = '',
@@ -685,6 +744,10 @@ L.TileLayer = L.GridLayer.extend({
this._map._socket.sendMessage('mouse type=' + type +
' x=' + x + ' y=' + y + ' count=' + count +
' buttons=' + buttons + ' modifier=' + modifier);
+
+ if (type === 'buttondown') {
+ this._clearSearchResults();
+ }
},
_postKeyboardEvent: function(type, charcode, keycode) {
More information about the Libreoffice-commits
mailing list