From b0b85725adc4a402f4a6d7d141b90bf0dea20be9 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 30 Nov 2015 15:31:30 -0500 Subject: [PATCH] If a search for a translation is exactly the value, prioritize it --- app/controllers/admin/site_texts_controller.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/site_texts_controller.rb b/app/controllers/admin/site_texts_controller.rb index 18b9841d851..c40cc4ae2e4 100644 --- a/app/controllers/admin/site_texts_controller.rb +++ b/app/controllers/admin/site_texts_controller.rb @@ -20,8 +20,15 @@ class Admin::SiteTextsController < Admin::AdminController translations.each do |k, v| results << {id: k, value: v} end + results.sort! do |x, y| - (x[:id].size + x[:value].size) <=> (y[:id].size + y[:value].size) + if x[:value].casecmp(params[:q]) == 0 + -1 + elsif y[:value].casecmp(params[:q]) == 0 + 1 + else + (x[:id].size + x[:value].size) <=> (y[:id].size + y[:value].size) + end end end