1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-06-29 00:29:34 +00:00

Ensures that sequences of the same character are broken up properly.

This commit is contained in:
Thomas Harte 2020-02-29 19:22:54 -05:00
parent 672c59f970
commit 41d2062342

View File

@ -49,8 +49,12 @@ void Typer::run_for(const HalfCycles duration) {
void Typer::append(const std::string &string) {
// Remove any characters that are already completely done;
// otherwise things may accumulate here indefinitely.
string_.erase(string_.begin(), string_.begin() + ssize_t(string_pointer_));
string_pointer_ = 0;
// Note that sequence_for_character may seek to look one backwards,
// so keep 'the character before' if there was one.
if(string_pointer_ > 1) {
string_.erase(string_.begin(), string_.begin() + ssize_t(string_pointer_) - 1);
string_pointer_ = 1;
}
// If the final character in the string is not Typer::EndString
// then this machine doesn't need Begin and End, so don't worry about it.
@ -85,10 +89,13 @@ uint16_t Typer::try_type_next_character() {
++phase_;
// If this is the start of the output sequence, start with a reset all keys.
// Then pause unless the caracter mapper says not to.
// Then pause if either: (i) the machine requires it; or (ii) this is the same
// character that was just typed, in which case the gap in presses will need to
// be clear.
if(phase_ == 1) {
delegate_->clear_all_keys();
if(character_mapper_->needs_pause_after_reset_all_keys()) {
if(character_mapper_->needs_pause_after_reset_all_keys() ||
(string_pointer_ > 0 && string_[string_pointer_ - 1] == string_[string_pointer_])) {
return 0xffff; // Arbitrarily. Anything non-zero will do.
}
++phase_;