<commit_before>#include "ctextbrowser.h"
#include "text/cstructuredtext.h"
#include "system/ctimeelapsed.h"
#include "reader/creader.h"

DISABLE_COMPILER_WARNINGS
#include "ui_ctextbrowser.h"

#include <QDebug>
#include <QMenu>
RESTORE_COMPILER_WARNINGS

CTextBrowser::CTextBrowser(QWidget *parent, CReader& reader) :
	QDialog(parent),
	_reader(reader),
	ui(new Ui::CTextBrowser)
{
	ui->setupUi(this);

	ui->_textView->setContextMenuPolicy(Qt::CustomContextMenu);
	connect(ui->_textView, &QWidget::customContextMenuRequested, [this](QPoint pos){

		if (_firstCharacterIndexForFragment.empty())
			return;

		QMenu menu;
		QAction * readFromHereAction = menu.addAction("Read from here");
		QAction * result = menu.exec(ui->_textView->mapToGlobal(pos));
		if (result == readFromHereAction)
		{
			const int c = ui->_textView->textCursor().position();
			auto indexItem = std::lower_bound(_firstCharacterIndexForFragment.begin(), _firstCharacterIndexForFragment.end(), c);
			if (indexItem != _firstCharacterIndexForFragment.begin())
				--indexItem;

			const auto wordIndex = indexItem - _firstCharacterIndexForFragment.begin();
			_reader.goToWord(wordIndex);
		}<commit_msg>CTextBrowser: a word no longer has to be selected for "Read from here" to work. Closed #35.<commit_after>#include "ctextbrowser.h"
#include "text/cstructuredtext.h"
#include "system/ctimeelapsed.h"
#include "reader/creader.h"

DISABLE_COMPILER_WARNINGS
#include "ui_ctextbrowser.h"

#include <QDebug>
#include <QMenu>
RESTORE_COMPILER_WARNINGS

CTextBrowser::CTextBrowser(QWidget *parent, CReader& reader) :
	QDialog(parent),
	_reader(reader),
	ui(new Ui::CTextBrowser)
{
	ui->setupUi(this);

	ui->_textView->setContextMenuPolicy(Qt::CustomContextMenu);
	connect(ui->_textView, &QWidget::customContextMenuRequested, [this](QPoint pos){

		if (_firstCharacterIndexForFragment.empty())
			return;

		QMenu menu;
		QAction * readFromHereAction = menu.addAction("Read from here");
		QAction * result = menu.exec(ui->_textView->mapToGlobal(pos));
		if (result == readFromHereAction)
		{
			const int c = ui->_textView->cursorForPosition(pos).position();
			auto indexItem = std::lower_bound(_firstCharacterIndexForFragment.begin(), _firstCharacterIndexForFragment.end(), c);
			if (indexItem != _firstCharacterIndexForFragment.begin())
				--indexItem;

			const auto wordIndex = indexItem - _firstCharacterIndexForFragment.begin();
			_reader.goToWord(wordIndex);
		}
{'fraction_non_alphanumeric': 0.13043478260869565, 'fraction_numerical': 0.0008203445447087777, 'mean_word_length': 6.413373860182371, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4603709', 'n_tokens_mistral': 849, 'n_tokens_neox': 792, 'n_words': 146}