Erroneous behaviour with CreateSegmentPairProperties() in Sdl.FileTypeSupport.Framework.BilingualApi

While I was testing our internal MT plugin in Studio 2022 SR1 and when copying content from a custom viewpart in Editor to target segment, the following piece of code gave curious results

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
protected override void Execute()
{
EditorController editorController = SdlTradosStudio.Application.GetController<EditorController>();
var doc = editorController.ActiveDocument;
var test = editorController.ActiveDocument.Project.GetProjectStatistics();
MTEditorResultsViewPartController MTEditorController = SdlTradosStudio.Application.GetController<MTEditorResultsViewPartController>();
var activeSegmentPair = doc.GetActiveSegmentPair();
var suggestion = MTEditorController.CopyMtProposal();
if (suggestion != null && activeSegmentPair != null)
{
if (activeSegmentPair.Properties.IsLocked)
{
}
else
{
activeSegmentPair.Target.Clear();
var textProps = doc.PropertiesFactory.CreateTextProperties(suggestion.Translation);
activeSegmentPair.Target.Add(doc.ItemFactory.CreateText(textProps));
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

So every time I choose to copy content from viewpart to target segment, CreateSegmentPairProperties() changes the ID of the active segment pair. It seems to create a new segment pair with new ID on top of the old one. It counts the number of segment pairs in the active document, increments it by 1 and changes the ID to that, which will then cause "Sequence contains no matching element" as the segment pair ID doesn't match anymore. The change is irreversible and trying to cancel the edit crashes Studio.

The same piece of code is used in all versions of the plugin, but only in 2022 SR1 it produces these results. A quick fix is to just comment out that one line, so it's not that drastic, but I'd like to know if that's actually the intended behaviour for this method (creating a new segment pair by default) and is it just redundant to use it like this, as each segment pair seems to have ISegmentPairProperties without creating them first. This piece of code has probably been around since Studio 2014 era.

-Mikko

emoji