Skip to content

Commit 83082b1

Browse files
committed
fix some bugs in the text handling of the divs
1 parent 7a154ce commit 83082b1

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

media/regexworkbench.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,13 @@ function buildResultsTable(results, parent) {
8989

9090
table += '</table>';
9191

92-
$(parent).empty();
93-
$(parent).html($(table));
92+
$(parent).empty().html($(table));
9493
wireThClick();
9594
}
9695

9796
function match() {
98-
const regex = new MultiRegExp2(new RegExp($('#regex').val(), "g" + getSwitches()));
99-
const search = $('#search').html();
97+
const regex = new MultiRegExp2(new RegExp($('#regex').val(), getSwitches()));
98+
const search = $('#search').innerText();
10099
let results = [];
101100

102101
const execResults = regex.execForAllGroups(search, true);
@@ -111,7 +110,7 @@ function match() {
111110

112111
function matchAll() {
113112
const regex = new MultiRegExp2(new RegExp($('#regex').val(), "g" + getSwitches()));
114-
const search = $('#search').html();
113+
const search = $('#search').innerText();
115114

116115
let results = [];
117116
let iteration;
@@ -127,7 +126,7 @@ function matchAll() {
127126

128127
function split() {
129128
const regex = new RegExp($('#regex').val(), "g" + getSwitches());
130-
const search = $('#search').html();
129+
const search = $('#search').innerText();
131130

132131
const items = search.split(regex).map(s => s.replace(/[\r\n]/g, "&nbsp;"));
133132
const results = items.map(item => `<span class="nl">${item}</span>`).join('');
@@ -138,19 +137,19 @@ function split() {
138137
function replace() {
139138
match();
140139
const regex = new RegExp($('#regex').val(), getSwitches());
141-
const search = $('#search').html();
142-
const replacement = $('#replacement').html();
140+
const search = $('#search').innerText();
141+
const replacement = $('#replacement').innerText();
143142

144-
$('#replaced').val(search.replace(regex, replacement));
143+
$('#replaced').innerText(search.replace(regex, replacement));
145144
};
146145

147146
function replaceAll() {
148147
matchAll();
149148
const regex = new RegExp($('#regex').val(), "g" + getSwitches());
150-
const search = $('#search').html();
151-
const replacement = $('#replacement').html();
149+
const search = $('#search').innerText();
150+
const replacement = $('#replacement').innerText();
152151

153-
$('#replaced').html(search.replace(regex, replacement));
152+
$('#replaced').innerText(search.replace(regex, replacement));
154153
};
155154

156155
function processResults(r) {
@@ -206,8 +205,8 @@ function onReplacementChange(_) {
206205
function updateStateInHost() {
207206
const state = {
208207
regex: $('#regex').val(),
209-
search: $('#search').html(),
210-
replacement: $('#replacement').html(),
208+
search: $('#search').innerText(),
209+
replacement: $('#replacement').innerText(),
211210
mode: $('.mode-btn.selected')[0].id.replace("-btn", ""),
212211
switches: {
213212
i: $('#i-switch.selected').length > 0,
@@ -249,8 +248,8 @@ function infoWindow(msg) {
249248

250249
function setUiState(state) {
251250
$('#regex').val(state.regex);
252-
$('#search').html(state.search);
253-
$('#replacement').html(state.replacement);
251+
$('#search').innerText(state.search);
252+
$('#replacement').innerText(state.replacement);
254253

255254
const buttonId = `#${state.mode}-btn`;
256255
$(buttonId).click();
@@ -290,6 +289,16 @@ function wireThClick() {
290289
});
291290
}
292291

292+
jQuery.fn.extend({
293+
innerText: function (arg) {
294+
if (arguments.length == 0) {
295+
return $(this)[0].innerText;
296+
} else {
297+
$(this)[0].innerText = arg;
298+
}
299+
}
300+
});
301+
293302
$(document).ready(() => {
294303
applyVscodeThemeCss();
295304

0 commit comments

Comments
 (0)