draft request autocomplete suggestions

This commit is contained in:
yggverse 2024-04-16 22:22:32 +03:00
parent 5a4fba93f1
commit 75ab8eb069
2 changed files with 93 additions and 0 deletions

View file

@ -129,6 +129,31 @@
"length":
{
"max":1024
},
"autocomplete":
{
"enabled":true,
"inline":
{
"completion":true,
"selection":true
},
"key":
{
"length":1
},
"ignore":
{
"keycode":
[
111,
116
]
},
"result":
{
"limit":15
}
}
}
}

View file

@ -30,6 +30,10 @@ class Page
public \GtkProgressBar $progressbar;
public \GtkEntryCompletion $completion;
public \GtkListStore $suggestion;
public object $config;
public function __construct(
@ -202,6 +206,70 @@ class Page
0
);
// Init autocomplete
if ($this->config->header->entry->request->autocomplete->enabled)
{
$this->completion = new \GtkEntryCompletion();
$this->completion->set_inline_completion(
$this->config->header->entry->request->autocomplete->inline->completion
);
$this->completion->set_inline_selection(
$this->config->header->entry->request->autocomplete->inline->selection
);
$this->completion->set_minimum_key_length(
$this->config->header->entry->request->autocomplete->key->length
);
$this->completion->set_text_column(
0
);
$this->suggestion = new \GtkListStore(
\GObject::TYPE_STRING
);
$this->completion->set_model(
$this->suggestion
);
$this->request->connect(
'key-release-event',
function ($entry, $event)
{
if (
mb_strlen($entry->get_text()) >= $this->config->header->entry->request->autocomplete->key->length
&&
isset($event->key->keycode)
&&
!in_array(
$event->key->keycode,
$this->config->header->entry->request->autocomplete->ignore->keycode
)
) {
$this->suggestion->clear();
foreach ($this->app->database->getHistory(
$entry->get_text(), 0, $this->config->header->entry->request->autocomplete->result->limit
) as $suggestion)
{
$this->suggestion->append(
[
$suggestion->url
]
);
}
$this->request->set_completion(
$this->completion
);
}
}
);
}
// Go button
$this->go = \GtkButton::new_with_label(
$this->config->header->button->go->label