Skip to content

Commit

Permalink
CSS/Text selection: adds a few "-cr-hint:" tweaks
Browse files Browse the repository at this point in the history
One can use "-cr-hint: text-selection-inline",
"text-selection-block" and "text-selection-skip" to
target some elements and tweak how their text will
appear (or not) in user text selection.
Might be useful to exclude the content of ruby
annotations (<ruby><rt>) from text selection when
providing it to dict lookup or translation.
  • Loading branch information
poire-z committed Jun 5, 2020
1 parent ac882d9 commit 90565ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
5 changes: 4 additions & 1 deletion crengine/include/cssdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ enum css_cr_hint_t {
css_cr_hint_toc_level5,
css_cr_hint_toc_level6,
css_cr_hint_toc_ignore,
css_cr_hint_strut_confined
css_cr_hint_strut_confined,
css_cr_hint_text_selection_inline,
css_cr_hint_text_selection_block,
css_cr_hint_text_selection_skip
};

/// css length value
Expand Down
5 changes: 5 additions & 0 deletions crengine/src/lvstsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,11 @@ static const char * css_cr_hint_names[]={
// baseline and height (it could have been a non-standard named
// value for line-height:, but we want to be able to not override
// existing line-height: values)

// Tweak text selection when traversing a node with these hints
"text-selection-inline", // don't add a '\n' before inner text, even if the node happens to be block
"text-selection-block", // add a '\n' before inner text even if the node happens to be inline
"text-selection-skip", // don't include inner text in text selection
NULL
};

Expand Down
15 changes: 14 additions & 1 deletion crengine/src/lvtinydom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11702,8 +11702,21 @@ class ldomTextCollector : public ldomNodeCallback
{
#if BUILD_LITE!=1
ldomNode * elem = (ldomNode *)ptr->getNode();
if ( elem->getRendMethod()==erm_invisible )
if ( elem->getRendMethod() == erm_invisible )
return false;
// Allow tweaking that with hints
css_cr_hint_t hint = elem->getStyle()->cr_hint;
if ( hint == css_cr_hint_text_selection_skip ) {
return false;
}
else if ( hint == css_cr_hint_text_selection_inline ) {
newBlock = false;
return true;
}
else if ( hint == css_cr_hint_text_selection_block ) {
newBlock = true;
return true;
}
switch ( elem->getStyle()->display ) {
/*
case css_d_inherit:
Expand Down

0 comments on commit 90565ff

Please sign in to comment.