Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into extension
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed Feb 10, 2024
2 parents af9fef8 + 0061e24 commit 0f73e21
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 58 deletions.
50 changes: 50 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
<a name="1.10.0"></a>
# [1.10.0](https://github.com/rime/librime/compare/1.9.0...1.10.0) (2024-02-09)


### Bug Fixes

* **chord_composer:** stop at super and caps by default ([8709a7a](https://github.com/rime/librime/commit/8709a7a))
* **path:** convert to native encoding on Windows ([#806](https://github.com/rime/librime/issues/806)) ([6546689](https://github.com/rime/librime/commit/6546689)), closes [#804](https://github.com/rime/librime/issues/804) [rime/weasel#576](https://github.com/rime/weasel/issues/576) [rime/weasel#1080](https://github.com/rime/weasel/issues/1080)
* don't compress the token during collecting dict entries ([#762](https://github.com/rime/librime/issues/762)) ([#768](https://github.com/rime/librime/issues/768)) ([767ebad](https://github.com/rime/librime/commit/767ebad))


### Features

* **api:** highlight_candidate*, change_page ([142902d](https://github.com/rime/librime/commit/142902d)), closes [#620](https://github.com/rime/librime/issues/620)
* **engine:** translate zero-length prediction ([8f2e8d6](https://github.com/rime/librime/commit/8f2e8d6))
* **key_binder:** add `when: predicting` condition ([#751](https://github.com/rime/librime/issues/751)) ([3bc65c9](https://github.com/rime/librime/commit/3bc65c9))
* **rime_api:** add RimeApi::set_input ([#771](https://github.com/rime/librime/issues/771)) ([de12d6a](https://github.com/rime/librime/commit/de12d6a)), closes [#547](https://github.com/rime/librime/issues/547)
* add reload command for rime_api_console ([#741](https://github.com/rime/librime/issues/741)) ([9b2689b](https://github.com/rime/librime/commit/9b2689b))


### Performance Improvements

* less nest in filesystem iteration When CleanOldLogFiles::Run ([#801](https://github.com/rime/librime/issues/801)) ([9ec1711](https://github.com/rime/librime/commit/9ec1711))


### BREAKING CHANGES

* **path:** Most `string` filenames in APIs are changed to `path`;
`installation.yaml` should be UTF-8 encoded.

Previouly on Windows, the file can be written in local encoding to
enable paths with non-ASCII characters. It should be updated to UTF-8
after this change.

Details of the code refactor

Wrap `std::filesystem::path` in a thin wrapper class `rime::path` which calls `std::filesystem::u8path` in the constructor on Windows.

Operator `/=` and `/` are also overloaded to convert the right operand from UTF-8 string to native path.

Follow these rules to apply correct conversion between `string` and `rime::path`:

- construct `rime::path` with UTF-8 encoded string;
- get native string by `path::u8string`;
- to extract UTF-8 string from `path`, for example to find schema ID from file name, call `path::u8string`;
- avoid implicit conversion from string, which results in `std::filesystem::path` without performing UTF-8 to native conversion;
- explicitly construct `rime::path` from `std::filesystem::path` before append operation, to ensure the overloaded operator with string conversion is used.



<a name="1.9.0"></a>
# [1.9.0](https://github.com/rime/librime/compare/1.8.5...1.9.0) (2023-09-16)

Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.12)
project(rime)
set(CMAKE_CXX_STANDARD 17)

set(rime_version 1.9.0)
set(rime_version 1.10.0)
set(rime_soversion 1)

add_definitions(-DRIME_VERSION="${rime_version}")
Expand Down
18 changes: 5 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ ifdef BUILD_UNIVERSAL
export CMAKE_OSX_ARCHITECTURES = arm64;x86_64
endif

# boost::locale library from homebrew links to homebrewed icu4c libraries
icu_prefix = $(shell brew --prefix)/opt/icu4c

else # for Linux
prefix ?= $(DESTDIR)/usr
endif
Expand All @@ -33,28 +30,23 @@ endif
debug install-debug uninstall-debug test-debug: build ?= debug
build ?= build

.PHONY: all deps thirdparty xcode clean \
librime librime-static install-librime uninstall-librime \
release debug test install uninstall install-debug uninstall-debug
.PHONY: all deps clean \
librime librime-static \
release debug test install uninstall \
install-debug uninstall-debug

all: release

# `thirdparty` is deprecated in favor of `deps`
deps thirdparty:
deps:
$(MAKE) -f deps.mk

deps/%:
$(MAKE) -f deps.mk $(@:deps/%=%)

thirdparty/%:
$(MAKE) -f deps.mk $(@:thirdparty/%=%)

clean:
rm -Rf build debug

librime: release
install-librime: install
uninstall-librime: uninstall

librime-static:
cmake . -B$(build) \
Expand Down
5 changes: 2 additions & 3 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,8 @@ cmake --build %build_dir% --config %build_config% --target install
if errorlevel 1 goto error

if "%build_test%" == "ON" (
pushd %build_dir%
ctest --output-on-failure
popd
ctest --test-dir %build_dir% -C %build_config% --output-on-failure
if errorlevel 1 goto error
)

echo.
Expand Down
17 changes: 17 additions & 0 deletions install-boost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ download_boost_source() {
[[ -f "${BOOST_ROOT}/bootstrap.sh" ]]
}

boost_cxxflags='-arch arm64 -arch x86_64'

build_boost_macos() {
[[ -n "${boost_libs}" ]] || return
cd "${BOOST_ROOT}"
./bootstrap.sh --with-toolset=clang --with-libraries="${boost_libs}"
./b2 -q -a link=static architecture=arm cxxflags="${boost_cxxflags}" stage
for lib in stage/lib/*.a; do
lipo $lib -info
done
}

if [[ $# -eq 0 || " $* " =~ ' --download ' ]]; then
if [[ ! -f "${BOOST_ROOT}/bootstrap.sh" ]]; then
download_boost_source
Expand All @@ -31,3 +43,8 @@ if [[ $# -eq 0 || " $* " =~ ' --download ' ]]; then
./bootstrap.sh
./b2 headers
fi
if [[ $# -eq 0 || " $* " =~ ' --build ' ]]; then
if [[ "$OSTYPE" =~ 'darwin' ]]; then
build_boost_macos
fi
fi
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "librime",
"version": "1.9.0",
"version": "1.10.0",
"description": "Rime Input Method Engine",
"main": "index.js",
"directories": {
Expand Down
26 changes: 17 additions & 9 deletions src/rime/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,26 @@ bool Context::Select(size_t index) {
return false;
}

bool Context::Hilite(size_t index) {
if (composition_.empty())
bool Context::Highlight(size_t index) {
if (composition_.empty() || !composition_.back().menu)
return false;
Segment& seg(composition_.back());
if (auto cand = seg.GetCandidateAt(index)) {
seg.selected_index = index;
seg.tags.insert("paging");
DLOG(INFO) << "Hilited: '" << cand->text() << "', index = " << index;
update_notifier_(this);
return true;
size_t new_index = index;
size_t candidate_count = seg.menu->Prepare(index + 1);
if (index >= candidate_count) {
DLOG(INFO) << "selection index exceeds candidate pool, fallback to last";
new_index = candidate_count - 1;
}
return false;
size_t previous_index = seg.selected_index;
if (previous_index == new_index) {
DLOG(INFO) << "selection has not changed, currently at " << new_index;
return false;
}
seg.selected_index = new_index;
update_notifier_(this);
DLOG(INFO) << "selection changed from: " << previous_index
<< " to: " << new_index;
return true;
}

bool Context::DeleteCandidate(
Expand Down
3 changes: 2 additions & 1 deletion src/rime/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class RIME_API Context {

// return false if there is no candidate at index
bool Select(size_t index);
bool Hilite(size_t index);
// return false if the selected index has not changed
bool Highlight(size_t index);
bool DeleteCandidate(size_t index);
// return false if there's no candidate for current segment
bool ConfirmCurrentSelection();
Expand Down
20 changes: 10 additions & 10 deletions src/rime/gear/simplifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ class Opencc {
for (const char* wstr = original_word.c_str(); *wstr != '\0';) {
opencc::Optional<const opencc::DictEntry*> matched =
dict->MatchPrefix(wstr);
size_t matchedLength;
size_t matched_length;
if (matched.IsNull()) {
matchedLength = opencc::UTF8Util::NextCharLength(wstr);
buffer << opencc::UTF8Util::FromSubstr(wstr, matchedLength);
matched_length = opencc::UTF8Util::NextCharLength(wstr);
buffer << opencc::UTF8Util::FromSubstr(wstr, matched_length);
} else {
matchedLength = matched.Get()->KeyLength();
matched_length = matched.Get()->KeyLength();
buffer << matched.Get()->GetDefault();
}
wstr += matchedLength;
wstr += matched_length;
}
const string& converted_word = buffer.str();
// Even if current dictionary doesn't convert the word
Expand Down Expand Up @@ -125,16 +125,16 @@ class Opencc {
for (const char* pstr = phrase; *pstr != '\0';) {
opencc::Optional<const opencc::DictEntry*> matched =
dict->MatchPrefix(pstr);
size_t matchedLength;
size_t matched_length;
if (matched.IsNull()) {
matchedLength = opencc::UTF8Util::NextCharLength(pstr);
buffer << opencc::UTF8Util::FromSubstr(pstr, matchedLength);
matched_length = opencc::UTF8Util::NextCharLength(pstr);
buffer << opencc::UTF8Util::FromSubstr(pstr, matched_length);
} else {
matchedLength = matched.Get()->KeyLength();
matched_length = matched.Get()->KeyLength();
size_t i = rand() % (matched.Get()->NumValues());
buffer << matched.Get()->Values().at(i);
}
pstr += matchedLength;
pstr += matched_length;
}
*simplified = buffer.str();
phrase = simplified->c_str();
Expand Down
48 changes: 37 additions & 11 deletions src/rime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1066,22 +1066,46 @@ static bool do_with_candidate_on_current_page(
return (ctx->*verb)(page_start + index);
}

RIME_API Bool RimeSelectCandidate(RimeSessionId session_id, size_t index) {
return do_with_candidate(session_id, index, &Context::Select);
Bool RimeChangePage(RimeSessionId session_id, Bool backward) {
an<Session> session(Service::instance().GetSession(session_id));
if (!session)
return False;
Context* ctx = session->context();
if (!ctx || !ctx->HasMenu())
return False;
Schema* schema = session->schema();
if (!schema)
return False;
size_t page_size = (size_t)schema->page_size();
auto& seg(ctx->composition().back());
size_t current_index = seg.selected_index;
size_t index =
backward ? (current_index <= page_size ? 0 : current_index - page_size)
: (current_index + page_size);
DLOG(INFO) << "current selection: " << current_index << ", flipping "
<< (backward ? "backward" : "forward") << ", new selection "
<< index;
seg.tags.insert("paging");
return ctx->Highlight(index);
}

RIME_API Bool RimeSelectCandidateOnCurrentPage(RimeSessionId session_id,
size_t index) {
return do_with_candidate_on_current_page(session_id, index, &Context::Select);
Bool RimeHighlightCandidate(RimeSessionId session_id, size_t index) {
return do_with_candidate(session_id, index, &Context::Highlight);
}

RIME_API Bool RimeHiliteCandidate(RimeSessionId session_id, size_t index) {
return do_with_candidate(session_id, index, &Context::Hilite);
Bool RimeHighlightCandidateOnCurrentPage(RimeSessionId session_id,
size_t index) {
return do_with_candidate_on_current_page(session_id, index,
&Context::Highlight);
}

RIME_API Bool RimeHiliteCandidateOnCurrentPage(RimeSessionId session_id,
RIME_API Bool RimeSelectCandidate(RimeSessionId session_id, size_t index) {
return do_with_candidate(session_id, index, &Context::Select);
}

RIME_API Bool RimeSelectCandidateOnCurrentPage(RimeSessionId session_id,
size_t index) {
return do_with_candidate_on_current_page(session_id, index, &Context::Hilite);
return do_with_candidate_on_current_page(session_id, index, &Context::Select);
}

const char* RimeGetVersion() {
Expand Down Expand Up @@ -1257,8 +1281,6 @@ RIME_API RimeApi* rime_get_api() {
s_api.context_proto = nullptr;
s_api.status_proto = nullptr;
s_api.get_state_label = &RimeGetStateLabel;
s_api.hilite_candidate = &RimeHiliteCandidate;
s_api.hilite_candidate_on_current_page = &RimeHiliteCandidateOnCurrentPage;
s_api.delete_candidate = &RimeDeleteCandidate;
s_api.delete_candidate_on_current_page = &RimeDeleteCandidateOnCurrentPage;
s_api.get_state_label_abbreviated = &RimeGetStateLabelAbbreviated;
Expand All @@ -1270,6 +1292,10 @@ RIME_API RimeApi* rime_get_api() {
s_api.get_prebuilt_data_dir_s = &RimeGetPrebuiltDataDirSecure;
s_api.get_staging_dir_s = &RimeGetStagingDirSecure;
s_api.get_sync_dir_s = &RimeGetSyncDirSecure;
s_api.highlight_candidate = &RimeHighlightCandidate;
s_api.highlight_candidate_on_current_page =
&RimeHighlightCandidateOnCurrentPage;
s_api.change_page = &RimeChangePage;
}
return &s_api;
}
15 changes: 8 additions & 7 deletions src/rime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,6 @@ RIME_API Bool RimeCandidateListFromIndex(RimeSessionId session_id,
RIME_API Bool RimeSelectCandidate(RimeSessionId session_id, size_t index);
RIME_API Bool RimeSelectCandidateOnCurrentPage(RimeSessionId session_id,
size_t index);
RIME_API Bool RimeHiliteCandidate(RimeSessionId session_id, size_t index);
RIME_API Bool RimeHiliteCandidateOnCurrentPage(RimeSessionId session_id,
size_t index);
RIME_API Bool RimeDeleteCandidate(RimeSessionId session_id, size_t index);
RIME_API Bool RimeDeleteCandidateOnCurrentPage(RimeSessionId session_id,
size_t index);
Expand Down Expand Up @@ -649,10 +646,6 @@ typedef struct rime_api_t {
const char* option_name,
Bool state);

Bool (*hilite_candidate)(RimeSessionId session_id, size_t index);
Bool (*hilite_candidate_on_current_page)(RimeSessionId session_id,
size_t index);

//! delete a candidate at the given index in candidate list.
Bool (*delete_candidate)(RimeSessionId session_id, size_t index);
//! delete a candidate from current page.
Expand All @@ -673,6 +666,14 @@ typedef struct rime_api_t {
void (*get_prebuilt_data_dir_s)(char* dir, size_t buffer_size);
void (*get_staging_dir_s)(char* dir, size_t buffer_size);
void (*get_sync_dir_s)(char* dir, size_t buffer_size);

//! highlight a selection without committing
Bool (*highlight_candidate)(RimeSessionId session_id, size_t index);
//! highlight a selection without committing
Bool (*highlight_candidate_on_current_page)(RimeSessionId session_id,
size_t index);

Bool (*change_page)(RimeSessionId session_id, Bool backward);
} RimeApi;

//! API entry
Expand Down
5 changes: 3 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ endif(BUILD_SHARED_LIBS)
file(GLOB test_data_files ${PROJECT_SOURCE_DIR}/data/test/*.yaml)
file(COPY ${test_data_files} DESTINATION ${EXECUTABLE_OUTPUT_PATH})

set(rime_test_executable ${EXECUTABLE_OUTPUT_PATH}/rime_test${ext})
add_test(rime_test ${rime_test_executable})
add_test(NAME rime_test
COMMAND rime_test
WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH})

0 comments on commit 0f73e21

Please sign in to comment.