Skip to content

Commit ae8fd6c

Browse files
authored
Merge pull request #29 from yacchin1205/fix/update-hash-after-rich-texts
Fix misalignment of replacements when updating hashes after itemized text
2 parents 2a83c33 + fa0694c commit ae8fd6c

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/pad/database/hash.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { SearchEngine, PadType } from "ep_search/setup";
22
import { tokenize } from "../static/js/parser";
33
import { logPrefix } from "../util/log";
44
import { getHashQuery } from "../static/js/hash";
5-
import { applyReplaceSet, ReplaceSet } from "./text";
5+
import { applyReplaceSet, ReplaceSet, getAText } from "./text";
66

77
const api = require("ep_etherpad-lite/node/db/API");
88
const { decode, encode } = require("he");
@@ -62,7 +62,7 @@ function replaceHash(text: string, updates: HashUpdate[]): ReplaceSet[] {
6262
}
6363

6464
export async function updateHash(padId: string, updates: HashUpdate[]) {
65-
const { text } = await api.getText(padId);
65+
const { text } = await getAText(padId);
6666
console.debug(
6767
logPrefix,
6868
"Update hash with text",

src/pad/database/text.ts

+5
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,8 @@ export async function applyReplaceSet(
5757
}
5858
await padMessageHandler.updatePadClients(pad);
5959
}
60+
61+
export async function getAText(padID: string) {
62+
const pad = await getPadSafe(padID, true);
63+
return pad.atext;
64+
}

src/pad/database/title.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import removeMdBase from "remove-markdown";
33
import { searchHashes, updateHash } from "./hash";
44
import { logPrefix } from "../util/log";
55
import { escapeForText } from "../static/js/result";
6-
import { applyReplaceSet, ReplaceSet } from "./text";
6+
import { applyReplaceSet, ReplaceSet, getAText } from "./text";
77

88
const api = require("ep_etherpad-lite/node/db/API");
99
const db = require("ep_etherpad-lite/node/db/DB").db;
@@ -67,7 +67,7 @@ async function updateTitleContent(
6767
newTitle: string
6868
): Promise<TitleUpdateResult> {
6969
console.info(logPrefix, "Update title", pad.id, oldTitle, newTitle);
70-
const { text } = await api.getText(pad.id);
70+
const { text } = await getAText(pad.id);
7171
const replaceSet = replaceTitle(text, oldTitle, newTitle);
7272
if (replaceSet === null) {
7373
console.warn(logPrefix, "Title not found in HTML", oldTitle, newTitle);

0 commit comments

Comments
 (0)