CharacterMap: select Unicode block for current character

* Scrolling the list of characters now selects the currently visible
block in the blocks list.

Signed-off-by: Adrien Destugues <pulkomandy@gmail.com>

Fixes #3651, part 1
This commit is contained in:
dsizzle 2014-11-23 19:47:32 +00:00 committed by Adrien Destugues
parent 67d659f26e
commit 74d9b875c2
4 changed files with 28 additions and 0 deletions

View File

@ -108,6 +108,12 @@ CharacterView::IsShowingBlock(int32 blockIndex) const
void
CharacterView::ScrollToBlock(int32 blockIndex)
{
// don't scroll if the selected character is already in view.
// this prevents distracting jumps when crossing a block
// boundary in the character view.
if (IsCharacterVisible(fCurrentCharacter))
return;
if (blockIndex < 0)
blockIndex = 0;
else if (blockIndex >= (int32)kNumUnicodeBlocks)

View File

@ -319,6 +319,8 @@ CharacterWindow::MessageReceived(BMessage* message)
fGlyphView->SetText(glyph);
fCodeView->SetText(text);
fUnicodeBlockView->SelectBlockForCharacter(character);
break;
}

View File

@ -118,3 +118,22 @@ UnicodeBlockView::_CreateBlocks()
_UpdateBlocks();
}
void
UnicodeBlockView::SelectBlockForCharacter(uint32 character)
{
// find block containing the character
// TODO: could use binary search here
for (uint32 i = 0; i < kNumUnicodeBlocks; i++) {
if (kUnicodeBlocks[i].end < character)
continue;
if (kUnicodeBlocks[i].start > character) {
// Character is not mapped
break;
}
Select(i);
ScrollToSelection();
}
}

View File

@ -40,6 +40,7 @@ public:
{ return fShowContainedBlocksOnly; }
bool IsShowingBlock(int32 blockIndex) const;
void SelectBlockForCharacter(uint32 character);
private:
void _UpdateBlocks();