#include "support/lstrings.h"
#include "support/lyxtime.h"
#include "support/os.h"
+#include "support/regex.h"
#include "mathed/InsetMathHull.h"
#include "mathed/MathMacroTemplate.h"
lyx::dispatch(FuncRequest(LFUN_DEPTH_DECREMENT));
}
bool const morecont = cur.lastpos() > cur.pos();
- lyx::dispatch(FuncRequest(LFUN_LAYOUT, "Separator"));
+ // FIXME This hardcoding is bad
+ docstring const sep =
+ cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))
+ ? from_ascii("Separator") : from_ascii("--Separator--");
+ lyx::dispatch(FuncRequest(LFUN_LAYOUT, sep));
lyx::dispatch(FuncRequest(LFUN_PARAGRAPH_BREAK, "inverse"));
if (morecont)
lyx::dispatch(FuncRequest(LFUN_DOWN));
bool const hebrew =
par.getFontSettings(bufparams, pos).language()->lang() == "hebrew";
bool const allow_inset_quote = !(par.isPassThru() || hebrew);
-
+
+ string const arg = to_utf8(cmd.argument());
if (allow_inset_quote) {
char_type c = ' ';
if (pos > 0 && (!cur.prevInset() || !cur.prevInset()->isSpace()))
c = par.getChar(pos - 1);
- string const arg = to_utf8(cmd.argument());
InsetQuotes::QuoteTimes const quote_type = (arg == "single")
? InsetQuotes::SingleQuotes : InsetQuotes::DoubleQuotes;
cur.insert(new InsetQuotes(cur.buffer(), c, quote_type));
} else {
// The cursor might have been invalidated by the replaceSelection.
cur.buffer()->changed(true);
- lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, "\""));
- }
+ string const quote_string = (arg == "single") ? "'" : "\"";
+ lyx::dispatch(FuncRequest(LFUN_SELF_INSERT, quote_string));
+ }
break;
}
}
case LFUN_HREF_INSERT: {
- InsetCommandParams p(HYPERLINK_CODE);
- docstring content;
+ // FIXME If we're actually given an argument, shouldn't
+ // we use it, whether or not we have a selection?
+ docstring content = cmd.argument();
if (cur.selection()) {
content = cur.selectionAsString(false);
cutSelection(cur, true, false);
}
- p["target"] = (cmd.argument().empty()) ?
- content : cmd.argument();
+
+ InsetCommandParams p(HYPERLINK_CODE);
+ if (!content.empty()){
+ // if it looks like a link, we'll put it as target,
+ // otherwise as name (bug #8792).
+
+ // We can't do:
+ // regex_match(to_utf8(content), matches, link_re)
+ // because smatch stores pointers to the substrings rather
+ // than making copies of them. And those pointers become
+ // invalid after regex_match returns, since it is then
+ // being given a temporary object. (Thanks to Georg for
+ // figuring that out.)
+ regex const link_re("^([a-z]+):.*");
+ smatch matches;
+ string const c = to_utf8(lowercase(content));
+
+ if (c.substr(0,7) == "mailto:") {
+ p["target"] = content;
+ p["type"] = from_ascii("mailto:");
+ } else if (regex_match(c, matches, link_re)) {
+ p["target"] = content;
+ string protocol = matches.str(1);
+ if (protocol == "file")
+ p["type"] = from_ascii("file:");
+ } else
+ p["name"] = content;
+ }
string const data = InsetCommand::params2string(p);
+
+ // we need to have a target. if we already have one, then
+ // that gets used at the default for the name, too, which
+ // is probably what is wanted.
if (p["target"].empty()) {
bv->showDialog("href", data);
} else {
code = INDEX_CODE;
else if (cmd.argument() == "index_print")
code = INDEX_PRINT_CODE;
+ else if (cmd.argument() == "listings")
+ code = LISTINGS_CODE;
+ else if (cmd.argument() == "mathspace")
+ code = MATH_HULL_CODE;
else if (cmd.argument() == "nomenclature")
code = NOMENCL_CODE;
else if (cmd.argument() == "nomencl_print")
code = VSPACE_CODE;
else if (cmd.argument() == "wrap")
code = WRAP_CODE;
- else if (cmd.argument() == "listings")
- code = LISTINGS_CODE;
break;
case LFUN_ERT_INSERT:
case LFUN_NEWLINE_INSERT:
// LaTeX restrictions (labels or empty par)
- enable = (cur.pos() > cur.paragraph().beginOfBody());
+ enable = !cur.paragraph().isPassThru()
+ && cur.pos() > cur.paragraph().beginOfBody();
break;
case LFUN_TAB_INSERT:
break;
case LFUN_ENVIRONMENT_SPLIT: {
- if (!cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))) {
+ // FIXME This hardcoding is bad
+ if (!cur.buffer()->params().documentClass().hasLayout(from_ascii("Separator"))
+ && !cur.buffer()->params().documentClass().hasLayout(from_ascii("--Separator--"))) {
enable = false;
break;
}