mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Set language to OS input language when moving cursor
Instead of setting language from context when moving the cursor, set it to the OS input language. This behavior will probably need to be controlled by a preference, since not everybody changes keyboard mapping when changing language. This required to move BufferView::setCursorLanguage to Cursor::setLanguageFromInput().
This commit is contained in:
parent
36399e88d3
commit
6f8298b165
@ -2739,17 +2739,6 @@ Cursor const & BufferView::cursor() const
|
||||
}
|
||||
|
||||
|
||||
void BufferView::setCursorLanguage(std::string const & code)
|
||||
{
|
||||
Language const * lang = languages.getFromCode(code, buffer_.getLanguages());
|
||||
if (lang) {
|
||||
d->cursor_.current_font.setLanguage(lang);
|
||||
d->cursor_.real_current_font.setLanguage(lang);
|
||||
} else
|
||||
LYXERR0("setCursorLanguage: unknown language code " << code);
|
||||
}
|
||||
|
||||
|
||||
bool BufferView::singleParUpdate()
|
||||
{
|
||||
Text & buftext = buffer_.text();
|
||||
|
@ -267,12 +267,6 @@ public:
|
||||
/// sets cursor.
|
||||
/// This is used when handling LFUN_MOUSE_PRESS.
|
||||
bool mouseSetCursor(Cursor & cur, bool select = false);
|
||||
/// Set the cursor language from language code.
|
||||
/* Considers first exact math with the codes used in the document,
|
||||
* then approximate match among the same list, and finally exact
|
||||
* or partial match with the whole list of languages.
|
||||
*/
|
||||
void setCursorLanguage(std::string const & code);
|
||||
|
||||
/// sets the selection.
|
||||
/* When \c backwards == false, set anchor
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "DispatchResult.h"
|
||||
#include "FuncCode.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "Language.h"
|
||||
#include "Layout.h"
|
||||
#include "LyXAction.h"
|
||||
#include "LyXRC.h"
|
||||
@ -51,6 +52,8 @@
|
||||
#include "mathed/MathFactory.h"
|
||||
#include "mathed/InsetMathMacro.h"
|
||||
|
||||
#include "frontends/Application.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
@ -2396,6 +2399,18 @@ bool notifyCursorLeavesOrEnters(Cursor const & old, Cursor & cur)
|
||||
}
|
||||
|
||||
|
||||
void Cursor::setLanguageFromInput()
|
||||
{
|
||||
string const & code = theApp()->inputLanguageCode();
|
||||
Language const * lang = languages.getFromCode(code, buffer()->getLanguages());
|
||||
if (lang) {
|
||||
current_font.setLanguage(lang);
|
||||
real_current_font.setLanguage(lang);
|
||||
} else
|
||||
LYXERR0("setLanguageFromCode: unknown language code " << code);
|
||||
}
|
||||
|
||||
|
||||
void Cursor::setCurrentFont()
|
||||
{
|
||||
CursorSlice const & cs = innerTextSlice();
|
||||
@ -2429,6 +2444,9 @@ void Cursor::setCurrentFont()
|
||||
current_font = par.getFontSettings(bufparams, cpos);
|
||||
real_current_font = tm.displayFont(cpit, cpos);
|
||||
|
||||
// set language to input language
|
||||
setLanguageFromInput();
|
||||
|
||||
// special case for paragraph end
|
||||
if (cs.pos() == lastpos()
|
||||
&& tm.isRTLBoundary(cpit, cs.pos())
|
||||
|
@ -279,7 +279,13 @@ public:
|
||||
/// get the resut of the last dispatch
|
||||
DispatchResult const & result() const;
|
||||
|
||||
///
|
||||
/// Set the cursor language from current input method language
|
||||
/* Considers first exact math with the codes used in the document,
|
||||
* then approximate match among the same list, and finally exact
|
||||
* or partial match with the whole list of languages.
|
||||
*/
|
||||
void setLanguageFromInput();
|
||||
/// Set the current font of the cursor from its location.
|
||||
void setCurrentFont();
|
||||
|
||||
/**
|
||||
|
@ -390,7 +390,7 @@ Match match(string const & code, Language const & lang)
|
||||
if ((code.size() == 2) && (langcode.size() > 2)
|
||||
&& (code + '_' == langcode.substr(0, 3)))
|
||||
return ApproximateMatch;
|
||||
if (code.substr(0,2) == langcode.substr(0,2))
|
||||
if (code.substr(0,2) == langcode.substr(0,2))
|
||||
return VeryApproximateMatch;
|
||||
return NoMatch;
|
||||
}
|
||||
|
@ -2129,7 +2129,7 @@ string GuiApplication::inputLanguageCode() const
|
||||
QLocale loc = inputMethod()->locale();
|
||||
#endif
|
||||
//LYXERR0("input lang = " << fromqstr(loc.name()));
|
||||
return fromqstr(loc.name());
|
||||
return loc.name() == "C" ? "en_US" : fromqstr(loc.name());
|
||||
}
|
||||
|
||||
|
||||
@ -2137,7 +2137,7 @@ void GuiApplication::onLocaleChanged()
|
||||
{
|
||||
//LYXERR0("Change language to " << inputLanguage()->lang());
|
||||
if (currentView() && currentView()->currentBufferView())
|
||||
currentView()->currentBufferView()->setCursorLanguage(inputLanguageCode());
|
||||
currentView()->currentBufferView()->cursor().setLanguageFromInput();
|
||||
}
|
||||
|
||||
|
||||
@ -2749,7 +2749,7 @@ bool GuiApplication::event(QEvent * e)
|
||||
case QEvent::KeyboardLayoutChange:
|
||||
//LYXERR0("keyboard change");
|
||||
if (currentView() && currentView()->currentBufferView())
|
||||
currentView()->currentBufferView()->setCursorLanguage(inputLanguageCode());
|
||||
currentView()->currentBufferView()->cursor().setLanguageFromInput();
|
||||
e->accept();
|
||||
return true;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user