Skip to content

Commit

Permalink
Merge pull request #29 from yacchin1205/fix/update-hash-after-rich-texts
Browse files Browse the repository at this point in the history
Fix misalignment of replacements when updating hashes after itemized text
  • Loading branch information
yacchin1205 authored Aug 27, 2024
2 parents 2a83c33 + fa0694c commit ae8fd6c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/pad/database/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SearchEngine, PadType } from "ep_search/setup";
import { tokenize } from "../static/js/parser";
import { logPrefix } from "../util/log";
import { getHashQuery } from "../static/js/hash";
import { applyReplaceSet, ReplaceSet } from "./text";
import { applyReplaceSet, ReplaceSet, getAText } from "./text";

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

export async function updateHash(padId: string, updates: HashUpdate[]) {
const { text } = await api.getText(padId);
const { text } = await getAText(padId);
console.debug(
logPrefix,
"Update hash with text",
Expand Down
5 changes: 5 additions & 0 deletions src/pad/database/text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ export async function applyReplaceSet(
}
await padMessageHandler.updatePadClients(pad);
}

export async function getAText(padID: string) {
const pad = await getPadSafe(padID, true);
return pad.atext;
}
4 changes: 2 additions & 2 deletions src/pad/database/title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import removeMdBase from "remove-markdown";
import { searchHashes, updateHash } from "./hash";
import { logPrefix } from "../util/log";
import { escapeForText } from "../static/js/result";
import { applyReplaceSet, ReplaceSet } from "./text";
import { applyReplaceSet, ReplaceSet, getAText } from "./text";

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

0 comments on commit ae8fd6c

Please sign in to comment.