diff --git a/src/apps/charactermap/CharacterView.cpp b/src/apps/charactermap/CharacterView.cpp index 529e2a9e1f..3f311e3d41 100644 --- a/src/apps/charactermap/CharacterView.cpp +++ b/src/apps/charactermap/CharacterView.cpp @@ -38,6 +38,7 @@ CharacterView::CharacterView(const char* name) fCharacterFont.SetSize(fCharacterFont.Size() * 1.5f); _UpdateFontSize(); + DoLayout(); } @@ -108,10 +109,10 @@ CharacterView::IsShowingBlock(int32 blockIndex) const void CharacterView::ScrollToBlock(int32 blockIndex) { - // don't scroll if the selected character is already in view. + // don't scroll if the selected block is already in view. // this prevents distracting jumps when crossing a block // boundary in the character view. - if (IsCharacterVisible(fCurrentCharacter)) + if (IsBlockVisible(blockIndex)) return; if (blockIndex < 0) @@ -141,6 +142,19 @@ CharacterView::IsCharacterVisible(uint32 c) const } +bool +CharacterView::IsBlockVisible(int32 block) const +{ + int32 topBlock = _BlockAt(BPoint(Bounds().left, Bounds().top)); + int32 bottomBlock = _BlockAt(BPoint(Bounds().right, Bounds().bottom)); + + if (block >= topBlock && block <= bottomBlock) + return true; + + return false; +} + + /*static*/ void CharacterView::UnicodeToUTF8(uint32 c, char* text, size_t textSize) { diff --git a/src/apps/charactermap/CharacterView.h b/src/apps/charactermap/CharacterView.h index 8c08d50925..fc5e618695 100644 --- a/src/apps/charactermap/CharacterView.h +++ b/src/apps/charactermap/CharacterView.h @@ -33,6 +33,7 @@ public: void ScrollToBlock(int32 blockIndex); void ScrollToCharacter(uint32 c); bool IsCharacterVisible(uint32 c) const; + bool IsBlockVisible(int32 block) const; static void UnicodeToUTF8(uint32 c, char* text, size_t textSize); diff --git a/src/apps/charactermap/CharacterWindow.cpp b/src/apps/charactermap/CharacterWindow.cpp index 2fd183b88f..77964c0edc 100644 --- a/src/apps/charactermap/CharacterWindow.cpp +++ b/src/apps/charactermap/CharacterWindow.cpp @@ -275,6 +275,8 @@ CharacterWindow::CharacterWindow() fUnicodeBlockView->SetTarget(this); fFilterControl->MakeFocus(); + + fUnicodeBlockView->SelectBlockForCharacter(0); } diff --git a/src/apps/charactermap/UnicodeBlockView.cpp b/src/apps/charactermap/UnicodeBlockView.cpp index a643875cb8..b40e40b30c 100644 --- a/src/apps/charactermap/UnicodeBlockView.cpp +++ b/src/apps/charactermap/UnicodeBlockView.cpp @@ -133,7 +133,13 @@ UnicodeBlockView::SelectBlockForCharacter(uint32 character) break; } - Select(i); - ScrollToSelection(); + BlockListItem* block = fBlocks.ItemAt(i); + + int32 blockNum = IndexOf(block); + + if (blockNum >= 0) { + Select(blockNum); + ScrollToSelection(); + } } }