@@ -172,7 +172,7 @@ class CanvasActivity : AppCompatActivity() {
172172 ProcessLifecycleOwner .get().lifecycleScope.launch {
173173 viewModel.closeSession(path, finalMetadata)
174174 }
175-
175+
176176 // Finish after data capture
177177 finish()
178178 }
@@ -330,14 +330,6 @@ class CanvasActivity : AppCompatActivity() {
330330 }
331331 binding.toolbarContainer.addView(composeToolbar)
332332
333- binding.toolbarContainer.setOnTouchListener { _, event ->
334- if (event.action == android.view.MotionEvent .ACTION_DOWN ) {
335- lifecycleScope.launch { binding.canvasView.getController().clearSelection() }
336- binding.canvasView.dismissActionPopup()
337- }
338- false
339- }
340-
341333 sidebarController =
342334 SettingsSidebarController (
343335 this ,
@@ -634,11 +626,22 @@ class CanvasActivity : AppCompatActivity() {
634626 targetRect : android.graphics.Rect ,
635627 ) {
636628 Logger .d(" NotateDebug" , " handleToolClick ID=$toolId " )
637- lifecycleScope.launch { binding.canvasView.getController().clearSelection() }
629+
630+ val item = viewModel.toolbarItems.value.find { it.id == toolId }
631+ val isSelectionSafeTool =
632+ when (item) {
633+ is ToolbarItem .Pen -> item.penTool.type == ToolType .TEXT
634+ is ToolbarItem .Select -> true
635+ else -> false
636+ }
637+
638+ // If clicking same tool (opening settings) OR switching to TEXT/SELECT, preserve selection.
639+ if (viewModel.activeToolId.value != toolId && ! isSelectionSafeTool) {
640+ lifecycleScope.launch { binding.canvasView.getController().clearSelection() }
641+ }
638642 binding.canvasView.dismissActionPopup()
639643
640644 if (viewModel.activeToolId.value == toolId) {
641- val item = viewModel.toolbarItems.value.find { it.id == toolId }
642645 val tool =
643646 when (item) {
644647 is ToolbarItem .Pen -> item.penTool
@@ -651,7 +654,17 @@ class CanvasActivity : AppCompatActivity() {
651654 com.alexdremov.notate.ui.dialog.PenSettingsPopup (
652655 this ,
653656 tool,
654- onUpdate = { updatedTool -> viewModel.updateTool(updatedTool) },
657+ onUpdate = { updatedTool ->
658+ viewModel.updateTool(updatedTool)
659+ if (updatedTool.type == ToolType .TEXT ) {
660+ lifecycleScope.launch {
661+ binding.canvasView.getController().updateSelectedTextStyle(
662+ fontSize = updatedTool.width,
663+ color = updatedTool.color,
664+ )
665+ }
666+ }
667+ },
655668 onRemove = { toolToRemove -> viewModel.removePen(toolToRemove.id) },
656669 onDismiss = {
657670 com.alexdremov.notate.util.EpdFastModeController
0 commit comments