Rename fix-string.js and fixTextForSvg function name to a more readable name.

User regex to detect arabic characters.

Fix editing bugs.
This commit is contained in:
Milad Karbasizadeh
2017-01-02 14:48:22 +03:30
parent 92b5ce133d
commit af1ac89df7
3 changed files with 17 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ import { geoExtent } from '../geo/index';
import { osmEntity, osmNode, osmRelation, osmWay } from '../osm/index';
import { utilDetect } from '../util/detect';
import { utilRebind } from '../util/rebind';
import { fixTextForSvg } from '../core/fix-string';
import { fixArabicScriptTextForSvg } from '../util/svg_paths_arabic_fix';
var dispatch = d3.dispatch('authLoading', 'authDone', 'change', 'loading', 'loaded'),
@@ -71,10 +71,11 @@ function getTags(obj) {
var attrs = elems[i].attributes;
tags[attrs.k.value] = attrs.v.value;
}
var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1
if(tags.name && tags.highway && !isFirefox){
var isFirefox = utilDetect().browser.toLowerCase().indexOf('firefox') > -1
var arabicRegex = /[\u0600-\u06FF]/g
if(tags.name && tags.highway && !isFirefox && arabicRegex.test(tags.name)){
tags.real_name = tags.name;
tags.name = fixTextForSvg(tags.real_name);
tags.name = fixArabicScriptTextForSvg(tags.real_name);
}
return tags;
}

View File

@@ -12,6 +12,7 @@ import { uiRawTagEditor } from './raw_tag_editor';
import { uiTagReference } from './tag_reference';
import { uiPreset } from './preset';
import { utilRebind } from '../util/rebind';
import { fixArabicScriptTextForSvg } from '../util/svg_paths_arabic_fix';
export function uiEntityEditor(context) {
@@ -224,6 +225,14 @@ export function uiEntityEditor(context) {
tags[k] = v;
}
});
var arabicRegex = /[\u0600-\u06FF]/g
if(tags.highway && tags.real_name){
if(arabicRegex.test(tags.real_name)){
tags.name = fixArabicScriptTextForSvg(tags.real_name);
} else{
tags.name = tags.real_name;
}
}
if (!onInput) {
tags = clean(tags);

View File

@@ -34,13 +34,13 @@ const chars = {
5000: {initial: "ﻻ", isolated: "ﻻ", medial: "", final: "ﻼ" }
};
export function fixTextForSvg(inputText){
export function fixArabicScriptTextForSvg(inputText){
return inputText.split(' ').reverse().map(function(w){
return fixWordForSvg(w);
return fixArabicScriptWordForSvg(w);
}).join(' ');
}
export function fixWordForSvg(inputWord){
export function fixArabicScriptWordForSvg(inputWord){
let context = true;
let ret = [];
//const inputWord = inputWord.split('');