Skip to content

Commit 29020c2

Browse files
committed
feat: allow adding new mappings
1 parent f9d181e commit 29020c2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

editor/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ <h1>ASCII Unicode Conversion Map Editor</h1>
105105
import { parse } from 'opentype'
106106
const ASCII_START = 33;
107107
const ASCII_END = 256;
108+
const append = (data, line) => {
109+
if (data === "") return line + '\n';
110+
if (data.slice(-1) === '\n') return data + line + '\n';
111+
return data + '\n' + line + '\n';
112+
}
108113
createApp({
109114
setup() {
110115
const asciiChars = [];
@@ -134,18 +139,23 @@ <h1>ASCII Unicode Conversion Map Editor</h1>
134139
}
135140
},
136141
changeMapping(char, value) {
142+
let modified = false;
137143
this.mapValue = this.mapValue
138144
.split('\n')
139145
.map(line => {
140146
if (line.startsWith('#')) return line;
141147
let [lhs, rhs] = line.split('=').map(w => w.trim())
142148
if (lhs === char) {
149+
modified = true;
143150
return `${lhs}=${value}`
144151
} else {
145152
return line
146153
}
147154
})
148155
.join('\n')
156+
if (!modified) {
157+
this.mapValue = append(this.mapValue, `${char}=${value}`)
158+
}
149159
},
150160
getCharCode(text) {
151161
if (!text) return "";

0 commit comments

Comments
 (0)