]> git.lyx.org Git - lyx.git/blobdiff - src/BufferList.cpp
* Rename HunspellSpellChecker to HunspellChecker and ASpell to AspellChecker for...
[lyx.git] / src / BufferList.cpp
index 4f6c848452c7605a09065ade1548493f47842af1..0ff0fa697cddcd6a7b1525ca82eb501f9405a40e 100644 (file)
@@ -316,7 +316,7 @@ Buffer * BufferList::getBuffer(support::FileName const & fname) const
                bind(equal_to<FileName>(), bind(&Buffer::fileName, _1), fname));
        if (it != bstore.end())
                        return *it;
-       // 2) possibly expensive test, using quivalence test of file names
+       // 2) possibly expensive test, using equivalence test of file names
        it = find_if(bstore.begin(), bstore.end(),
                bind(equivalent_to(), bind(&Buffer::fileName, _1), fname));
        return it != bstore.end() ? (*it) : 0;
@@ -327,9 +327,26 @@ Buffer * BufferList::getBufferFromTmp(string const & s)
 {
        BufferStorage::iterator it = bstore.begin();
        BufferStorage::iterator end = bstore.end();
-       for (; it < end; ++it)
-               if (prefixIs(s, (*it)->temppath()))
-                       return *it;
+       for (; it < end; ++it) {
+               if (prefixIs(s, (*it)->temppath())) {
+                       // check whether the filename matches the master
+                       string const master_name = changeExtension(onlyFilename(
+                                               (*it)->absFileName()), ".tex");
+                       if (suffixIs(s, master_name))
+                               return *it;
+                       // if not, try with the children
+                       vector<Buffer *> clist = (*it)->getChildren();
+                       vector<Buffer *>::const_iterator cit = clist.begin();
+                       vector<Buffer *>::const_iterator cend = clist.end();
+                       for (; cit < cend; ++cit) {
+                               string const mangled_child_name = DocFileName(
+                                       changeExtension((*cit)->absFileName(),
+                                               ".tex")).mangledFilename();
+                               if (suffixIs(s, mangled_child_name))
+                                       return *cit;
+                       }
+               }
+       }
        return 0;
 }