Fix up hspace reversion routine.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36045 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Richard Heck 2010-11-04 12:59:44 +00:00
parent 53f88eea18
commit 5d6f9b620d

View File

@ -1052,14 +1052,19 @@ def revert_percent_hspace_lengths(document):
i = find_token(document.body, "\\begin_inset space \\hspace", i)
if i == -1:
break
protected = (document.body[i].find("\\hspace*{}") != -1)
# only revert if a custom length was set and if
# it used a percent length
length = get_value(document.body, '\\length', i + 1)
j = find_end_of_inset(document.body, i)
if j == -1:
document.warning("Can't find end of inset at line " + str(i))
i += 1
continue
# only revert if a custom length was set...
length = get_value(document.body, '\\length', i + 1, j)
if length == '':
document.warning("Malformed lyx document: Missing '\\length' in Space inset.")
return
# handle percent lengths
i = j
continue
protected = (document.body[i].find("\\hspace*{}") != -1)
# ...and if it used a percent length
length = latex_length(length)
# latex_length returns "bool,length"
percent = length.split(",")[0]
@ -1067,11 +1072,12 @@ def revert_percent_hspace_lengths(document):
# revert the HSpace inset to ERT
if percent == "True":
if protected:
subst = [old_put_cmd_in_ert("\\hspace*{" + length + "}")]
subst = put_cmd_in_ert("\\hspace*{" + length + "}")
else:
subst = [old_put_cmd_in_ert("\\hspace{" + length + "}")]
document.body[i:i + 3] = subst
i = i + 2
subst = put_cmd_in_ert("\\hspace{" + length + "}")
document.body[i:j + 1] = subst
# if we did a substitution, this will still be ok
i = j
def revert_hspace_glue_lengths(document):