1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-23 13:52:26 +01:00

Turn favicons back on. Don't let the completion list jump. Move some stuff to vimperator.css.

This commit is contained in:
Kris Maglione
2008-10-05 05:10:15 +00:00
parent e5bce7c63c
commit 49e7229830
3 changed files with 52 additions and 33 deletions

View File

@@ -59,13 +59,7 @@ liberator.Completion = function () //{{{
.getService(Components.interfaces.nsIIOService); .getService(Components.interfaces.nsIIOService);
function getIcon(uri) function getIcon(uri)
{ {
return; return function () faviconService.getFaviconImageForPage(ioService.newURI(uri, null, null)).spec;
try
{
let img = faviconService.getFaviconImageForPage(ioService.newURI(uri, null, null));
return img.spec;
}
catch (e) {}
} }
function addIcon(elem) function addIcon(elem)
{ {
@@ -89,7 +83,7 @@ liberator.Completion = function () //{{{
// function uses smartcase // function uses smartcase
// list = [ [['com1', 'com2'], 'text'], [['com3', 'com4'], 'text'] ] // list = [ [['com1', 'com2'], 'text'], [['com3', 'com4'], 'text'] ]
function buildLongestCommonSubstring(list, filter) function buildLongestCommonSubstring(list, filter, favicon)
{ {
var filtered = []; var filtered = [];
@@ -113,7 +107,7 @@ liberator.Completion = function () //{{{
if (compitem.indexOf(filter) == -1) if (compitem.indexOf(filter) == -1)
continue; continue;
filtered.push([compitem, item[1], item[2]]); filtered.push([compitem, item[1], favicon ? item[2] : null]);
if (longest) if (longest)
{ {
@@ -129,7 +123,7 @@ liberator.Completion = function () //{{{
} }
// this function is case sensitive // this function is case sensitive
function buildLongestStartingSubstring(list, filter) function buildLongestStartingSubstring(list, filter, favicon)
{ {
var filtered = []; var filtered = [];
@@ -146,7 +140,7 @@ liberator.Completion = function () //{{{
if (compitem.indexOf(filter) != 0) if (compitem.indexOf(filter) != 0)
continue; continue;
filtered.push([compitem, item[1], item[2]]); filtered.push([compitem, item[1], favicon ? item[2] : null]);
if (longest) if (longest)
{ {
@@ -191,15 +185,15 @@ liberator.Completion = function () //{{{
// generic filter function, also builds substrings needed // generic filter function, also builds substrings needed
// for :set wildmode=list:longest, if necessary // for :set wildmode=list:longest, if necessary
filter: function (array, filter, matchFromBeginning) filter: function (array, filter, matchFromBeginning, favicon)
{ {
if (!filter) if (!filter)
return array; return [[a[0], a[1], favicon ? a[2] : null] for each (a in array)];
if (matchFromBeginning) if (matchFromBeginning)
return buildLongestStartingSubstring(array, filter); return buildLongestStartingSubstring(array, filter, favicon);
else else
return buildLongestCommonSubstring(array, filter); return buildLongestCommonSubstring(array, filter, favicon);
}, },
autocommand: function (filter) autocommand: function (filter)
@@ -300,9 +294,9 @@ liberator.Completion = function () //{{{
} }
if (tail) if (tail)
return [dir.length, buildLongestStartingSubstring(mapped, compl)]; return [dir.length, buildLongestStartingSubstring(mapped, compl, true)];
else else
return [0, buildLongestStartingSubstring(mapped, filter)]; return [0, buildLongestStartingSubstring(mapped, filter, true)];
}, },
javascript: function (str) javascript: function (str)
@@ -394,7 +388,7 @@ liberator.Completion = function () //{{{
{ {
var keywords = [[k[0], k[1], getIcon(k[2])] for each (k in liberator.bookmarks.getKeywords())]; var keywords = [[k[0], k[1], getIcon(k[2])] for each (k in liberator.bookmarks.getKeywords())];
var engines = liberator.bookmarks.getSearchEngines(); var engines = liberator.bookmarks.getSearchEngines();
return [0, this.filter(engines.concat(keywords), filter)]; return [0, this.filter(engines.concat(keywords), filter, false, true)];
}, },
// XXX: Move to bookmarks.js? // XXX: Move to bookmarks.js?

View File

@@ -1127,8 +1127,10 @@ liberator.CommandLine = function () //{{{
if (liberator.mode != liberator.modes.COMMAND_LINE) if (liberator.mode != liberator.modes.COMMAND_LINE)
return; return;
/* Only hide if not pending.
if (compl.length == 0) if (compl.length == 0)
return completionList.hide(); return completionList.hide();
*/
completionList.setItems(compl); completionList.setItems(compl);
@@ -1198,19 +1200,22 @@ liberator.ItemList = function (id) //{{{
var listOffset = -1; // how many items is the displayed list shifted from the internal tab index var listOffset = -1; // how many items is the displayed list shifted from the internal tab index
var listIndex = -1; // listOffset + listIndex = completions[item] var listIndex = -1; // listOffset + listIndex = completions[item]
var selectedElement = null; var selectedElement = null;
var minHeight = 0;
// TODO: temporary, to be changed/removed // TODO: temporary, to be changed/removed
function createRow(b, c, a, dom) function createRow(b, c, a, dom)
{ {
let row = let row =
<tr class="liberator-compitem"> <tr class="compitem">
<td style="width: 16px"/> <td class="favicon"/>
<td style="width: 45%; overflow: hidden">{b}</td> <td class="completion">{b}</td>
<td style="color: gray">{c}</td> <td class="description">{c}</td>
</tr> </tr>
if (typeof a == "function")
a = a();
if (a) if (a)
row.td[0].* = <img width="16px" height="16px" src={a}/>; row.td[0].* = <img src={a}/>;
if (dom) if (dom)
return liberator.util.xmlToDom(row, doc); return liberator.util.xmlToDom(row, doc);
@@ -1222,11 +1227,12 @@ liberator.ItemList = function (id) //{{{
function getHeight() function getHeight()
{ {
if (completionElements.length == 0) if (completionElements.length == 0)
return doc.height; return Math.max(minHeight, doc.height);
var wanted = Math.min(maxItems + listOffset, var wanted = Math.min(maxItems + listOffset,
completionElements.length); completionElements.length);
return completionElements[wanted - 1].getBoundingClientRect().bottom; minHeight = Math.max(minHeight, completionElements[wanted - 1].getBoundingClientRect().bottom);
return minHeight;
} }
var height = getHeight(); var height = getHeight();
@@ -1295,7 +1301,7 @@ liberator.ItemList = function (id) //{{{
doc.body.appendChild(liberator.util.xmlToDom(div, doc)); doc.body.appendChild(liberator.util.xmlToDom(div, doc));
completionElements = doc.getElementsByClassName("liberator-compitem"); completionElements = doc.getElementsByClassName("compitem");
autoSize(); autoSize();
} }
@@ -1307,7 +1313,18 @@ liberator.ItemList = function (id) //{{{
clear: function () { this.setItems([]); doc.body.innerHTML = ""; }, clear: function () { this.setItems([]); doc.body.innerHTML = ""; },
hide: function () { container.collapsed = true; }, hide: function () { container.collapsed = true; },
show: function () { container.collapsed = false; }, show: function ()
{
/* FIXME: Should only happen with autocomplete,
* possibly only with async entries.
*/
if (container.collapsed)
{
minHeight = 0;
autoSize();
}
container.collapsed = false;
},
visible: function () !container.collapsed, visible: function () !container.collapsed,
// if @param selectedItem is given, show the list and select that item // if @param selectedItem is given, show the list and select that item
@@ -1357,9 +1374,9 @@ liberator.ItemList = function (id) //{{{
fill(newOffset); fill(newOffset);
if (selectedElement) if (selectedElement)
selectedElement.style.backgroundColor = ""; selectedElement.removeAttribute("selected");
selectedElement = completionElements[index - newOffset]; selectedElement = completionElements[index - newOffset];
selectedElement.style.backgroundColor = "yellow"; selectedElement.setAttribute("selected", "true");
listIndex = index; listIndex = index;
return; return;

View File

@@ -26,6 +26,18 @@ the provisions above, a recipient may use your version of this file under
the terms of any one of the MPL, the GPL or the LGPL. the terms of any one of the MPL, the GPL or the LGPL.
}}} ***** END LICENSE BLOCK *****/ }}} ***** END LICENSE BLOCK *****/
@-moz-document
url-prefix(chrome://vimperator/),
url-prefix(chrome://muttator/) {
.compitem[selected=true] { background-color: yellow; }
.compitem .favicon { width: 16px; }
.compitem .favicon img { width: 16px; height: 16px; }
.compitem .completion { width: 45%; overflow: hidden; }
.compitem .description { color: gray; }
}
@-moz-document @-moz-document
url-prefix(chrome://vimperator/), url-prefix(chrome://vimperator/),
url-prefix(chrome://muttator/), url-prefix(chrome://muttator/),
@@ -50,10 +62,6 @@ the terms of any one of the MPL, the GPL or the LGPL.
color: HighlightText !important; color: HighlightText !important;
} }
/*.liberator-compitem {
min-height: 16px;
}*/
/* fixes the min-height: 22px from firefox */ /* fixes the min-height: 22px from firefox */
#status-bar, statusbarpanel { #status-bar, statusbarpanel {
-moz-appearance: none !important; -moz-appearance: none !important;