soul-browser/scripts/compile-find-whole-word.sh
KaKi87 b6d8280e2d
Add whole-word toggle to Find in page (#100)
* Add a whole-word toggle to Find in page.

Match-whole-word uses window.find so substring hits inside larger words are skipped; the Ab icon dims when off.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix Find in page crash from MainApp.E1 type mismatch.

The recompiled find bar loaded E1 as float; it is an int, so promote with int-to-float in dispatchDraw.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix Find in page crash from MainUtil.c8/X4 signatures.

Those helpers take View, not EditText; the recompiled find bar used the wrong descriptor.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Tighten Find bar layout and keep whole-word highlights.

Place the whole-word toggle between clear and the match count, use tighter equal action-icon spacing, and highlight every whole-word hit with mark tags instead of only the current selection.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Fix whole-word find returning 0/0 after the first mark.

Stop reassigning the text node to the right remnant when wrapping matches end-to-start, which broke later splitText offsets.

Co-authored-by: Cursor <cursoragent@cursor.com>

* Add a case-sensitive toggle left of whole-word in Find.

Native findAllAsync has no match-case option, so case-sensitive (alone or with whole-word) uses the same mark-based highlighter.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-08 18:44:54 +02:00

63 lines
2.3 KiB
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
SRC="${ROOT_DIR}/sources/java/com/mycompany/app/view/FindWholeWordHelper.java"
OUT_SMALI="${ROOT_DIR}/app/smali_classes4/com/mycompany/app/view"
TOOLS="${ROOT_DIR}/tools"
ANDROID_HOME="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-${HOME}/android-sdk}}"
ANDROID_JAR="$(ls -1 "${ANDROID_HOME}/platforms"/android-*/android.jar 2>/dev/null | sort -V | tail -1)"
D8="$(find "${ANDROID_HOME}/build-tools" -name d8 -type f 2>/dev/null | sort -V | tail -1)"
DEX_TOOLS_ZIP="${TOOLS}/dex-tools-v2.4.zip"
DEX_TOOLS_DIR="${TOOLS}/dex-tools-v2.4"
BAKSMALI_JAR="${TOOLS}/baksmali.jar"
mkdir -p "${TOOLS}" "${OUT_SMALI}"
if [[ ! -f "${ANDROID_JAR}" ]]; then
echo "error: android.jar not found" >&2
exit 1
fi
if [[ -z "${D8}" ]]; then
echo "error: d8 not found" >&2
exit 1
fi
if [[ ! -f "${DEX_TOOLS_DIR}/d2j-baksmali.sh" ]]; then
if [[ ! -f "${DEX_TOOLS_ZIP}" ]]; then
echo "Downloading dex-tools v2.4..."
curl -fsSL -o "${DEX_TOOLS_ZIP}" \
"https://github.com/pxb1988/dex2jar/releases/download/v2.4/dex-tools-v2.4.zip"
fi
unzip -qo "${DEX_TOOLS_ZIP}" -d "${TOOLS}"
fi
chmod +x "${DEX_TOOLS_DIR}/"*.sh "${DEX_TOOLS_DIR}/d2j_invoke.sh" 2>/dev/null || true
if [[ ! -f "${BAKSMALI_JAR}" ]]; then
echo "Downloading baksmali 2.5.2..."
curl -fsSL -o "${BAKSMALI_JAR}" \
"https://repo1.maven.org/maven2/org/smali/baksmali/2.5.2/baksmali-2.5.2.jar"
fi
STAGE="$(mktemp -d)"
cleanup() { rm -rf "${STAGE}"; }
trap cleanup EXIT
echo "Compiling FindWholeWordHelper.java..."
javac --release 11 -classpath "${ANDROID_JAR}" -d "${STAGE}/classes" "${SRC}"
echo "Dexing..."
mkdir -p "${STAGE}/out"
"${D8}" --release --output "${STAGE}/out" "${STAGE}/classes/com/mycompany/app/view/"*.class
echo "Disassembling to smali..."
if [[ -x "${DEX_TOOLS_DIR}/d2j-baksmali.sh" ]]; then
bash "${DEX_TOOLS_DIR}/d2j-baksmali.sh" -f -o "${STAGE}/smali" "${STAGE}/out/classes.dex"
else
java -cp "${BAKSMALI_JAR}" org.jf.baksmali.Main d "${STAGE}/out/classes.dex" -o "${STAGE}/smali"
fi
rm -f "${OUT_SMALI}"/FindWholeWordHelper*.smali
mkdir -p "${OUT_SMALI}"
cp -f "${STAGE}/smali/com/mycompany/app/view/"FindWholeWordHelper*.smali "${OUT_SMALI}/"
echo "Wrote $(ls "${OUT_SMALI}"/FindWholeWordHelper*.smali | wc -l) smali file(s) to ${OUT_SMALI}"