From 3279fe8b07c7f15770eda33145f112f335c68303 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Fri, 9 Aug 2024 11:47:46 +0800 Subject: [PATCH 1/5] opt: fulltext next navigation optimization (#1718) * opt: fulltext dialog navigation optimization. The fulltext dialog navigation (next,previous) use webview's findText,try to find the longest word for navigation --- src/ui/articleview.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc index 08faee3f..8e30bfaf 100644 --- a/src/ui/articleview.cc +++ b/src/ui/articleview.cc @@ -2111,10 +2111,18 @@ void ArticleView::highlightFTSResults() webview->page()->runJavaScript( script ); auto parts = regString.split( " ", Qt::SkipEmptyParts ); - if ( !parts.isEmpty() ) { - firstAvailableText = parts[ 0 ]; - ftsSearchPanel->show(); + if ( parts.isEmpty() ) { + return; } + + //hold the longest word + for ( auto & p : parts ) { + if ( p.size() > firstAvailableText.size() ) { + firstAvailableText = p; + } + } + + ftsSearchPanel->show(); } void ArticleView::setActiveDictIds( const ActiveDictIds & ad ) From 388924033a40a39e430e8596de2936ebe56203de Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Fri, 9 Aug 2024 14:33:00 +0800 Subject: [PATCH 2/5] doc: add document about move index folder (#1719) * doc: add document about move index folder * doc: add document about move index folder --- website/docs/topic_move_index_folder.md | 17 +++++++++++++++++ website/mkdocs.yml | 1 + 2 files changed, 18 insertions(+) create mode 100644 website/docs/topic_move_index_folder.md diff --git a/website/docs/topic_move_index_folder.md b/website/docs/topic_move_index_folder.md new file mode 100644 index 00000000..59617d44 --- /dev/null +++ b/website/docs/topic_move_index_folder.md @@ -0,0 +1,17 @@ +How to move the default index folder to other places? + + +## Windows + +!!! note + the [`mklink`](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/mklink#related-links) is built-in tool in Windows. + + +1. Open `cmd` as administrator +2. copy the index folder to another place,take `D:\gd-ng\index_new` for example. +3. Run `mklink /D "C:\Users\USERNAME\Application Data\GoldenDict\index" "D:\gd-ng\index_new"` +4. Run GoldenDict + +## Linux + +use `ln` to create a link. diff --git a/website/mkdocs.yml b/website/mkdocs.yml index ed69f837..c7aecc4a 100644 --- a/website/mkdocs.yml +++ b/website/mkdocs.yml @@ -46,6 +46,7 @@ nav: - Wayland: topic_wayland.md - Debug dictionary JS: howto/how to debug dictionary js.md - Flatpak/FlatHub: topic_flatpak.md + - Move index folder: topic_move_index_folder.md - Related tools: - Anki Integration: topic_anki.md - OCR Integration: howto/ocr.md From 65ae8f50309390b65661e1e5515c01d8854e58bc Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Sat, 10 Aug 2024 10:46:44 +0800 Subject: [PATCH 3/5] opt: smells (#1721) * opt: remove code smell for loop should avoid change the iterators * opt: remove code smell for loop should avoid change the iterators --- src/article_maker.cc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/article_maker.cc b/src/article_maker.cc index 6508bcba..9ce0ff4f 100644 --- a/src/article_maker.cc +++ b/src/article_maker.cc @@ -282,20 +282,16 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const & bool ignoreDiacritics ) const { if ( !dictIDs.isEmpty() ) { - QStringList ids = dictIDs; - std::vector< sptr< Dictionary::Class > > ftsDicts; + std::vector< sptr< Dictionary::Class > > dicts; // Find dictionaries by ID's - for ( unsigned x = 0; x < dictionaries.size(); x++ ) { - for ( QStringList::Iterator it = ids.begin(); it != ids.end(); ++it ) { - if ( *it == QString::fromStdString( dictionaries[ x ]->getId() ) ) { - ftsDicts.push_back( dictionaries[ x ] ); - ids.erase( it ); + for ( const auto & dictId : dictIDs ) { + for ( unsigned x = 0; x < dictionaries.size(); x++ ) { + if ( dictId == QString::fromStdString( dictionaries[ x ]->getId() ) ) { + dicts.push_back( dictionaries[ x ] ); break; } } - if ( ids.isEmpty() ) - break; } string header = makeHtmlHeader( word, QString(), true ); @@ -303,7 +299,7 @@ sptr< Dictionary::DataRequest > ArticleMaker::makeDefinitionFor( QString const & return std::make_shared< ArticleRequest >( word, Instances::Group{ groupId, "" }, contexts, - ftsDicts, + dicts, header, -1, true ); From 6b4936ade4e53719185d1e936939b1afe10442aa Mon Sep 17 00:00:00 2001 From: Xiao Yi Fang Date: Sat, 10 Aug 2024 13:41:23 +0800 Subject: [PATCH 4/5] fix: close file when return error --- src/dictzip.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/dictzip.c b/src/dictzip.c index 51b26586..7615c873 100644 --- a/src/dictzip.c +++ b/src/dictzip.c @@ -416,8 +416,9 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header if ( ftell( str ) != header->headerLength + 1 ) { err_internal( __func__, "File position (%lu) != header length + 1 (%d)\n", ftell( str ), header->headerLength + 1 ); fclose( str ); - if ( header->chunks ) + if ( header->chunks ) { free( header->chunks ); + } return DZ_ERR_INVALID_FORMAT; } @@ -435,8 +436,10 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header /* Compute offsets */ header->offsets = xmalloc( sizeof( header->offsets[ 0 ] ) * header->chunkCount ); if ( header->offsets == 0 ) { - if ( header->chunks ) + if ( header->chunks ) { free( header->chunks ); + } + fclose( str ); return DZ_ERR_NOMEMORY; } From 752b880f248616fb32c1c2c44ac9ed7dac6d1b2a Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Sat, 10 Aug 2024 14:59:50 +0800 Subject: [PATCH 5/5] fix: double release memory (#1722) * fix: double release memory --- src/dictzip.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/dictzip.c b/src/dictzip.c index 7615c873..60496075 100644 --- a/src/dictzip.c +++ b/src/dictzip.c @@ -371,8 +371,10 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header if ( pt == buffer + sizeof( buffer ) ) { err_fatal( __func__, "too long FNAME field in dzip file \"%s\"\n", filename ); fclose( str ); - if ( header->chunks ) + if ( header->chunks ) { free( header->chunks ); + header->chunks = NULL; + } return DZ_ERR_INVALID_FORMAT; } } @@ -393,8 +395,10 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header if ( pt == buffer + sizeof( buffer ) ) { err_fatal( __func__, "too long COMMENT field in dzip file \"%s\"\n", filename ); fclose( str ); - if ( header->chunks ) + if ( header->chunks ) { free( header->chunks ); + header->chunks = NULL; + } return DZ_ERR_INVALID_FORMAT; } } @@ -418,6 +422,7 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header fclose( str ); if ( header->chunks ) { free( header->chunks ); + header->chunks = NULL; } return DZ_ERR_INVALID_FORMAT; } @@ -438,6 +443,7 @@ static enum DZ_ERRORS dict_read_header( const char * filename, dictData * header if ( header->offsets == 0 ) { if ( header->chunks ) { free( header->chunks ); + header->chunks = NULL; } fclose( str ); return DZ_ERR_NOMEMORY;