[gnome-maps] placeEntry: Make auto-complete accent insensitive
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] placeEntry: Make auto-complete accent insensitive
- Date: Sun, 13 Mar 2016 18:09:49 +0000 (UTC)
commit 213825b5735e693ba8a14956b077639660059202
Author: Marius Stanciu <stanciumarius94 gmail com>
Date: Sat Mar 12 17:49:00 2016 +0200
placeEntry: Make auto-complete accent insensitive
https://bugzilla.gnome.org/show_bug.cgi?id=763392
src/place.js | 5 +++--
src/placeListRow.js | 6 ++++--
src/utils.js | 8 ++++++++
3 files changed, 15 insertions(+), 4 deletions(-)
---
diff --git a/src/place.js b/src/place.js
index ad22b7d..0d85b96 100644
--- a/src/place.js
+++ b/src/place.js
@@ -24,6 +24,7 @@ const GLib = imports.gi.GLib;
const Lang = imports.lang;
const Location = imports.location;
const Translations = imports.translations;
+const Utils = imports.utils;
// Matches coordinates string with the format "<lat>, <long>"
const COORDINATES_REGEX = /^\s*(\-?\d+(?:\.\d+)?)\s*,\s*(\-?\d+(?:\.\d+)?)\s*$/;
@@ -248,14 +249,14 @@ const Place = new Lang.Class({
if (!name)
return false;
- searchString = GLib.utf8_normalize(searchString, -1, GLib.NormalizeMode.ALL);
+ searchString = Utils.normalizeString(searchString);
if (searchString === null)
return false;
if (searchString.length === 0)
return true;
- name = GLib.utf8_normalize(name, -1, GLib.NormalizeMode.ALL);
+ name = Utils.normalizeString(name);
if (name === null)
return false;
diff --git a/src/placeListRow.js b/src/placeListRow.js
index d4286fc..bba694f 100644
--- a/src/placeListRow.js
+++ b/src/placeListRow.js
@@ -23,6 +23,7 @@ const Lang = imports.lang;
const PlaceFormatter = imports.placeFormatter;
const PlaceStore = imports.placeStore;
+const Utils = imports.utils;
const ROW_HEIGHT = 55;
@@ -71,9 +72,10 @@ const PlaceListRow = new Lang.Class({
},
_boldMatch: function(title, string) {
- string = string.toLowerCase();
+ let canonicalString = Utils.normalizeString(string).toLowerCase();
+ let canonicalTitle = Utils.normalizeString(title).toLowerCase();
- let index = title.toLowerCase().indexOf(string);
+ let index = canonicalTitle.indexOf(canonicalString);
if (index !== -1) {
let substring = title.substring(index, index + string.length);
diff --git a/src/utils.js b/src/utils.js
index 41453d8..f9c7151 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -35,6 +35,9 @@ const IMPERIAL_SYSTEM = 2;
//List of locales using imperial system according to glibc locale database
const IMPERIAL_LOCALES = ['unm_US', 'es_US', 'es_PR', 'en_US', 'yi_US'];
+// Matches all unicode stand-alone accent characters
+const ACCENTS_REGEX = /[\u0300-\u036F]/g;
+
let debugInit = false;
let debugEnabled = false;
let measurementSystem = null;
@@ -380,3 +383,8 @@ function uriSchemeSupported(scheme) {
}
return false;
}
+
+function normalizeString(string) {
+ let normalized = GLib.utf8_normalize(string, -1, GLib.NormalizeMode.ALL);
+ return normalized.replace(ACCENTS_REGEX, '');
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]