Skip to content

Commit

Permalink
Merge pull request #3817 from Hannah-Sten/bib-line-endings
Browse files Browse the repository at this point in the history
Fix line endings for bibtex entry from remote file
  • Loading branch information
PHPirates authored Dec 22, 2024
2 parents ef60f5e + eb222e9 commit d2fb156
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,36 @@
## [Unreleased]

### Added

### Fixed

## [0.9.10-alpha.4] - 2024-12-21

### Added

* Add sections to breadcrumbs
* Improve performance when starting a run configuration and when using autocompletion directly after starting the IDE
* Change order in structure view to match source file and sectioning level
* Add command redefinitions to command definition filter in structure view
* Add support for automatic language injection on the minted environment
* Add support for automatic detection of custom command aliases for include commands
* Add support for DeclareGraphicsExtensions
* Add inspection to warn about a missing reference for a glossary occurrence
* Do not fold sections in a command definition
* Include optional parameters in spellcheck, if it contains text
* Improve performance of finding files to be indexed
* Show formatted file path in file not found inspection quickfix name
* Automatically index bibliography files outside the project that are included by an absolute path
* Disable quotes inspection when TeX ligatures are disabled by fontspec
* Inspections can now be suppressed for any single line, or block of text

### Fixed

* Fix auto import from local bibtex file on Windows
* Fix false positive for duplicate command definition inspection in if/else
* Fix LaTeX files not showing up when choosing main file in run configuration
* Fix various issues with the Grazie implementation, in particular default rules for Grazie Pro

## [0.9.10-alpha.3] - 2024-12-15

### Added
Expand All @@ -27,6 +48,7 @@
* Inspections can now be suppressed for any single line, or block of text

### Fixed

* Fix false positive for duplicate command definition inspection in if/else
* Fix LaTeX files not showing up when choosing main file in run configuration
* Fix various issues with the Grazie implementation, in particular default rules for Grazie Pro
Expand Down Expand Up @@ -478,7 +500,8 @@ Thanks to @jojo2357 and @MisterDeenis for contributing to this release!
* Fix some intention previews. ([#2796](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2796))
* Other small bug fixes and improvements. ([#2776](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2776), [#2774](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2774), [#2765](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2765)-[#2773](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2773))

[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.10-alpha.3...HEAD
[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.10-alpha.4...HEAD
[0.9.10-alpha.4]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.10-alpha.3...v0.9.10-alpha.4
[0.9.10-alpha.3]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.10-alpha.2...v0.9.10-alpha.3
[0.9.10-alpha.2]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9...v0.9.10-alpha.2
[0.9.9]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.8...v0.9.9
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pluginVersion = 0.9.10-alpha.3
pluginVersion = 0.9.10-alpha.4

# Info about build ranges: https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
# Note that an xyz branch corresponds to version 20xy.z and a since build of xyz.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import com.intellij.codeInsight.completion.InsertionContext
import com.intellij.codeInsight.lookup.LookupElement
import nl.hannahsten.texifyidea.file.BibtexFile
import nl.hannahsten.texifyidea.psi.BibtexEntry
import nl.hannahsten.texifyidea.psi.LatexPsiHelper
import nl.hannahsten.texifyidea.settings.TexifySettings
import nl.hannahsten.texifyidea.util.files.bibtexIdsInFileSet
import nl.hannahsten.texifyidea.util.files.referencedFileSet
import nl.hannahsten.texifyidea.util.parser.firstChildOfType

/**
* @author Sten Wessel
Expand All @@ -20,18 +22,21 @@ class LatexReferenceInsertHandler(private val remote: Boolean = false, private v

if (remote and TexifySettings.getInstance().automaticBibtexImport) {
remoteBib ?: return
// remoteBib may come from a file with CRLF line separators, which cannot be accepted into a psi file, so we need to fix that
val newBibEntry = LatexPsiHelper(context.project).createBibtexFromText(remoteBib.text.replace("\r\n", "\n")).firstChildOfType(BibtexEntry::class) ?: return

val bibsInFile = context.file.originalFile.bibtexIdsInFileSet()
// Add the bib item after the last item we found in the file set, and hope that that makes sense...
bibsInFile.lastOrNull()?.let {
it.parent.addAfter(remoteBib, it)
it.parent.addAfter(newBibEntry, it)
}

// If there are no bib items in the fileset yet, see if there is a(n empty) bib file we can add the bib entry to.
if (bibsInFile.isEmpty()) {
context.file.originalFile
.referencedFileSet()
.firstOrNull { it is BibtexFile }
?.add(remoteBib)
?.add(newBibEntry)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/nl/hannahsten/texifyidea/psi/LatexPsiHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.PsiFileFactory
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.impl.source.tree.LeafPsiElement
import nl.hannahsten.texifyidea.grammar.BibtexLanguage
import nl.hannahsten.texifyidea.grammar.LatexLanguage
import nl.hannahsten.texifyidea.psi.LatexTypes.*
import nl.hannahsten.texifyidea.util.Log
Expand Down Expand Up @@ -57,6 +58,9 @@ class LatexPsiHelper(private val project: Project) {
fun createFromText(text: String): PsiFile =
PsiFileFactory.getInstance(project).createFileFromText("DUMMY.tex", LatexLanguage, text, false, true)

fun createBibtexFromText(text: String): PsiFile =
PsiFileFactory.getInstance(project).createFileFromText("DUMMY.bib", BibtexLanguage, text, false, true)

/**
* Adds the supplied element to the content of the environment.
* @param environment The environment whose content should be manipulated
Expand Down

0 comments on commit d2fb156

Please sign in to comment.