@@ -27,7 +27,9 @@ import {
2727 ChevronDown ,
2828 Type ,
2929 MoreHorizontal ,
30- BookOpen
30+ BookOpen ,
31+ Link2 ,
32+ Link2Off
3133} from "lucide" ;
3234import { on , emit } from "../core/events.js" ;
3335import { getState , setState } from "../core/state.js" ;
@@ -43,7 +45,7 @@ const THRESHOLD_LISTS = 520; // then lists
4345const THRESHOLD_TEXT = 420 ; // finally text formatting
4446
4547const allIcons = { Bold, Italic, Strikethrough, Underline, Code, Link, List, ListOrdered,
46- ListChecks, Quote, Minus, Table, FileCode, ChevronDown, Type, MoreHorizontal, Pencil, BookOpen } ;
48+ ListChecks, Quote, Minus, Table, FileCode, ChevronDown, Type, MoreHorizontal, Pencil, BookOpen, Link2 , Link2Off } ;
4749
4850export function initEmbeddedToolbar ( ) {
4951 toolbar = document . getElementById ( "toolbar" ) ;
@@ -76,13 +78,19 @@ function render() {
7678function renderReadMode ( ) {
7779 toolbar . innerHTML = `<div class="embedded-toolbar">
7880 <div class="toolbar-spacer"></div>
81+ <button class="toolbar-btn cursor-sync-btn active" id="emb-cursor-sync" data-tooltip="${ t ( "toolbar.cursor_sync" ) || "Cursor sync" } " aria-pressed="true">
82+ <i data-lucide="link-2" class="sync-on-icon"></i>
83+ <i data-lucide="link-2-off" class="sync-off-icon" style="display:none"></i>
84+ </button>
7985 <button class="edit-toggle-btn" id="emb-edit-btn" title="${ t ( "toolbar.switch_to_edit" ) || "Switch to edit mode" } ">
8086 <i data-lucide="pencil"></i>
8187 <span>${ t ( "toolbar.edit" ) || "Edit" } </span>
8288 </button>
8389 </div>` ;
8490
85- createIcons ( { icons : { Pencil } , attrs : { class : "" } } ) ;
91+ createIcons ( { icons : { Pencil, Link2, Link2Off } , attrs : { class : "" } } ) ;
92+
93+ wireCursorSyncButton ( ) ;
8694
8795 const editBtn = document . getElementById ( "emb-edit-btn" ) ;
8896 if ( editBtn ) {
@@ -166,6 +174,10 @@ function renderEditMode(level) {
166174 toolbar . innerHTML = `<div class="embedded-toolbar">
167175 ${ formatRow }
168176 <div class="toolbar-spacer"></div>
177+ <button class="toolbar-btn cursor-sync-btn active" id="emb-cursor-sync" data-tooltip="${ t ( "toolbar.cursor_sync" ) || "Cursor sync" } " aria-pressed="true">
178+ <i data-lucide="link-2" class="sync-on-icon"></i>
179+ <i data-lucide="link-2-off" class="sync-off-icon" style="display:none"></i>
180+ </button>
169181 <button class="done-btn" id="emb-done-btn" title="${ t ( "toolbar.switch_to_reader" ) || "Switch to reader mode" } ">
170182 <i data-lucide="book-open"></i>
171183 <span>${ t ( "toolbar.reader" ) || "Reader" } </span>
@@ -179,6 +191,7 @@ function renderEditMode(level) {
179191 if ( level > 0 ) {
180192 wireDropdowns ( ) ;
181193 }
194+ wireCursorSyncButton ( ) ;
182195 wireDoneButton ( ) ;
183196}
184197
@@ -251,6 +264,21 @@ function closeAllDropdowns() {
251264 }
252265}
253266
267+ function wireCursorSyncButton ( ) {
268+ const syncBtn = document . getElementById ( "emb-cursor-sync" ) ;
269+ if ( syncBtn ) {
270+ syncBtn . addEventListener ( "click" , ( ) => {
271+ const isActive = syncBtn . classList . toggle ( "active" ) ;
272+ syncBtn . setAttribute ( "aria-pressed" , String ( isActive ) ) ;
273+ const onIcon = syncBtn . querySelector ( ".sync-on-icon" ) ;
274+ const offIcon = syncBtn . querySelector ( ".sync-off-icon" ) ;
275+ if ( onIcon ) onIcon . style . display = isActive ? "" : "none" ;
276+ if ( offIcon ) offIcon . style . display = isActive ? "none" : "" ;
277+ emit ( "toggle:cursorSync" , { enabled : isActive } ) ;
278+ } ) ;
279+ }
280+ }
281+
254282function wireDoneButton ( ) {
255283 const doneBtn = document . getElementById ( "emb-done-btn" ) ;
256284 if ( doneBtn ) {
0 commit comments